Date()
is not part of jQuery
, it is one of JavaScript's features.
(Date()
不是jQuery
一部分,它是JavaScript的一个特性。)
See the documentation on Date object .
(请参阅Date对象的文档 。)
You can do it like that:
(你可以这样做:)
var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var output = d.getFullYear() + '/' +
(month<10 ? '0' : '') + month + '/' +
(day<10 ? '0' : '') + day;
See this jsfiddle for a proof.
(请参阅此jsfiddle以获取证据。)
The code may look like a complex one, because it must deal with months & days being represented by numbers less than 10
(meaning the strings will have one char instead of two).
(代码可能看起来很复杂,因为它必须处理由小于10
的数字表示的月和日(意味着字符串将有一个char而不是两个)。)
See this jsfiddle for comparison.(请参阅此jsfiddle进行比较。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…