Test Cases
const date1 = 'UTC 2015-08-07 09:13:36'
const dateParse1 = new Date(date1)
console.log(dateParse1.toString()) // Fri Aug 07 2015 09:13:36 GMT+0300 (GMT+03:00)
The date should be parsed as UTC
date, but, actually the output is GMT+0300
. why is that?
I also tried luxon
to parse this date, for example:
const { DateTime } = require('luxon')
const date1 = 'UTC 2015-08-07 09:13:36'
console.log(DateTime.fromISO(date1))
The output:
DateTime {
ts: 1624865766790,
_zone: LocalZone {},
loc: Locale {
locale: 'en-US',
numberingSystem: null,
outputCalendar: null,
intl: 'en-US',
weekdaysCache: { format: {}, standalone: {} },
monthsCache: { format: {}, standalone: {} },
meridiemCache: null,
eraCache: {},
specifiedLocale: null,
fastNumbersCached: null
},
invalid: Invalid {
reason: 'unparsable',
explanation: `the input "UTC 2015-08-07 09:13:36" can't be parsed as ISO 8601`
},
weekData: null,
c: null,
o: null,
isLuxonDateTime: true
}
I tried other fromXX
methods from luxon
with no luck.
What is the preferable method to parse and format date in JavaScript?
Note: 'UTC 2015-08-07 09:13:36' date was originally extracted from a video encoded date meta data.
Thanks!