admin管理员组文章数量:1389903
i have in jquery:
var start = '2012-11-10 13:10:13';
Why this not working:
var date = new Date(start);
? How can i make it without external plugins?
i have in jquery:
var start = '2012-11-10 13:10:13';
Why this not working:
var date = new Date(start);
? How can i make it without external plugins?
Share Improve this question edited Nov 6, 2012 at 11:48 raina77ow 107k16 gold badges204 silver badges236 bronze badges asked Nov 6, 2012 at 11:34 Berg SwootsBerg Swoots 1311 silver badge6 bronze badges 03 Answers
Reset to default 4This is a bit more correct:
var correctStart = '2012-11-10T13:10:13';
var date = new Date(correctStart);
Quoting the Date.parse
(MDN) doc:
Alternatively, the date/time string may be in ISO 8601 format. Starting with JavaScript 1.8.5 / Firefox 4, a subset of ISO 8601 is supported. For example, "2011-10-10" (just date) or "2011-10-10T14:48:00 (date and time) can be passed and parsed.
Still, this format is NOT supported by IE8 (as mentioned here). Therefore I suggest at least considering possibility of using external libraries for processing dates - in particular, Moment.js.
Or you Can try it as shown below
var start = '10/11/2012 13:10:13';
var date = new Date(start);
This is working
Refer this JSFIDDLE DEMO
You have to convert the date string from Y-m-d H:i:s
to Y/m/d H:i:s
because javascript does not recognize the date string in that format.
Do this:
var my_date = "2012-11-10 13:10:13";
my_date = my_date.replace(/-/g, "/"); //this will replace "-" with "/"
//alert(my_date);
var javascript_date = new Date(my_date);
本文标签: javascriptCreate object Date from text in format Ymd HisStack Overflow
版权声明:本文标题:javascript - Create object Date from text in format Y-m-d H:i:s - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744605042a2615302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论