[英]Date string formatting in dojo or javascript
I have my dateString in this format : 2013/05/04 00:00:00
. 我有以下格式的dateString:
2013/05/04 00:00:00
。 From this, I want to form date object in the form yyyy/MM/dd
in javascript or in dojo. 由此,我想在javascript或dojo中以
yyyy/MM/dd
的形式形成日期对象。 I tried using date.format
. 我尝试使用
date.format
。 But it is unable to understand the format and returning me null
. 但是它无法理解格式并返回
null
。 How can I do that? 我怎样才能做到这一点?
been answered, but if you using dojo, you can do it like this 已回答,但是如果您使用dojo,则可以这样做
require(["dojo/date/locale"], function(locale){
console.log(locale.format(new Date("2013/05/04 00:00:00"),{
selector: "date",
datePattern : "yyyy/MM/dd"
}));
})
I would investigate using a library like the one described in String.format for JavaScript . 我将研究使用类似String.format中描述的JavaScript库那样的库。 It is a little more functional than simple string parsing.
它比简单的字符串解析功能更多。
var d = new Date();
console.log(d.format("yyyy/MM/dd"); // prints 2013/05/30
Fiddle: http://jsfiddle.net/vVgTc/ 小提琴: http : //jsfiddle.net/vVgTc/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.