My log file contains timestamps in a non-ISO format:
2020-12-03 08:30:00
2020-12-03 08:40:00
...
The timestamps are in UTC, as per the log provider's documentation.
I am attempting to parse them using date-fns:
const toParse = "2020-12-03 08:40:00"
parse(toParse, 'yyyy-MM-dd HH:mm:ss', new Date()).toISOString()
Due to my computer's locale being UTC+1, I encounter this issue:
> "2020-12-03T07:40:00Z"
Instead, I expect:
> "2020-12-03T08:40:00Z".
To work around this, I currently append '+00' to parse as UTC:
const toParse = "2020-12-03 08:40:00"
parse(toParse + '+00', 'yyyy-MM-dd HH:mm:ss' + 'X', new Date()).toISOString()
This results in:
> "2020-12-03T08:40:00Z".
Is there a correct way to achieve this with date-fns? Seeking an equivalent of moment's moment.utc()