user3484934 user3484934 -4 years ago 145
Javascript Question

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

I want to use Date Object Methods (

getHoures(), getSeconds()
...) on
new Date("string") (string = month day, year hh:mm:ss
) but my date format is like this :
yyyy-mm-dd hh:mm:ss


So I need to convert
"yyyy-mm-dd hh:mm:ss"
to "(
"day, month date year hh:mm:ss"
)"

How can i do please ?

Thx !

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download