这个datetime格式是否有简单的转换? [英] Is there a simple conversion for this datetime format?
问题描述
从该webservice检索的date属性不是一个真正的 Date
,因为它不是一个公认的日期格式。
将其处理为Date对象的最简单的方法是用T替换空白空间:
var receivedDate =2009-07-01 07:30:09;
var serializedDate = new Date(receivedDate.replace(,T));
alert(serializedDate);
这不是最正确的,因为它不处理时区,但在大多数情况下都可以工作。
I'm retrieving data from a JSON feed using jQuery and as part of the feed I'm getting 'datetime' attributes like "2009-07-01 07:30:09". I want to put this information into a javascript Date object for easy use but I don't believe the Date object would recognize this kind of format if I simply plugged it into the constructor. Is there a function or maybe a clever trick I can use to quickly break down this format into something the Date object can recognize and use?
The "date" attribute you are retrieving from that webservice is not a real Date
, as it is not a recognized date format.
The easiest way to handle it as a Date object would be to replace the empty space with a "T":
var receivedDate = "2009-07-01 07:30:09";
var serializedDate = new Date(receivedDate.replace(" ", "T"));
alert(serializedDate);
This is not the most correct, as it is not handling timezones, but in most cases will work.
这篇关于这个datetime格式是否有简单的转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!