EXTJS 3 API to convert datetime
In the EXTJS 3, if I have a string like 'Fri Jul 13 00:00:00 EDT 2012' , how can I get date string '07/13/2012' ? Does EXTJS have some API to handle this ?
Thanks
---- Update --- I found a way, like this
if (Ext.isDate("Fri Jul 13 00:00:00 EDT 2012")) {
var date1 = new Date("Fri Jul 13 00:00:00 EDT 2012");
var start_str = date1.format('m/d/Y');
}
Im not sure about ExtJS specifically but there's a very similar question asked here and the answer links to the documentation; it's worth checking that question out just for the example in the answer though!
In a pure Javascript implementation a regex may be the way to go. There's quite a few Regex Examples available and even a few Generators which can make your life easier if you aren't too confident with regex. Here's an example of the generated code from that site - jsFiddle link. (Thats not the cleanest way of doing a regex, when you use a generator it actually leaves quite a lot to be desired unfortunately. But it does work and give a decent starting point! )
Upon closer inspection of the string, I notice it uses text to signify the month. This could be worked around via the use of an enum.
As far as ExtJS goes - there's a pretty good blog post here about some of the date format options. But I think the documentation linked at the top of the answer is the best place to be looking.
JavaScript的Date
对象应该在这里提供你需要的一切:
var d = new Date('Fri Jul 13 00:00:00 EDT 2012');
var out = (d.getMonth()+1) + '/' + d.getDate() + '/' + d.getFullYear()
链接地址: http://www.djcxy.com/p/91776.html
上一篇: 如何在JavaScript中创建枚举
下一篇: EXTJS 3 API转换日期时间