const time = '2016-11-16 00:00:00.000';
const date = new Date(time);
console.info(date);
It seems safari cannot parse yyyy-MM-dd HH:mm:ss.SSS format date( it returns NaN ) while chrome works fine, how can I parse this?
Date formatting Dates are formatted using the following format: "yyyy-MM-dd'T'hh:mm:ss'Z'" if in UTC or "yyyy-MM-dd'T'hh:mm:ss[+|-]hh:mm" otherwise. On the contrary to the time zone, by default the number of milliseconds is not displayed. However, when displayed, the format is: "yyyy-MM-dd'T'hh:mm:ss.
The toDateString() Method in JavaScript First three letters of the week day name. First three letters of the month name. Two digit day of the month, padded on the left a zero if necessary. Four digit year (at least), padded on the left with zeros if necessary.
I'd use momentjs for working with dates in javascript. Easy example:
var time = '2016-11-16 00:00:00.000';
var m = moment.utc(time, "YYYY-MM-DD HH:mm:ss.SSS");
console.log(m)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.16.0/moment-with-locales.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With