Javascript convert yyyy-mm-dd hh:mm:ss like newDate(“day, month date year hh:mm:ss”)

删除回忆录丶 提交于 2019-12-04 18:42:28

Actually, you don't need to perform any such conversion.

The string you have is already in very nearly an acceptable format for new Date(string) and in fact even as is will be accepted by most (if not all) modern browsers.

To make it fully compliant with the ISO8601 variant that ES5 mandates, just replace the space between the date and time with a literal T character, and add a time-zone specifier at the end (e.g. either Z for UTC, or +01:00, for example).

See http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15 for more.

Try this: JSFIDDLE there are many JavaScript libraries available. format 'yyyy-mm-dd hh:mm:ss' used by MySQL server. you can covert above string into date object using following code:

var arr = " yyyy-mm-dd hh:mm:ss".split(/-|\s|:/);// split string and create array.
var date = new Date(arr[0], arr[1] -1, arr[2], arr[3], arr[4], arr[5]); // decrease month value by 1

Try this:

d = Date().split(" "); var date = d[2] + "-" + d[1] + "-" + d[3] + " " + d[4]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!