简体   繁体   中英

Convert string to datetime and change GMT in javascript

i have a problems to convert and change the GMT, please i triyng with this new Date(date) jsfiddle , and i think this work, but i want change the format like this YYYY-mm-dd hh:mm:ss , but the result show "invalid format date", and i cant use the format function. Please help me

Javascript will not accept the date/time format you are passing to it. Convert the timestamp first, then pass the array values like this:

var t = "2015-06-23 21:07:33".split(/[- :]/);
var targetTime = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);

Here is an updated fiddle: http://jsfiddle.net/16ehj22d/2/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM