I have two strings which represent the date/time in Greenwich Mean Time (GMT) which I wish to convert to their Coordinated Universal Time (or UTC) equivalent.
2019-11-01 09:58
2019-10-01 08:58
For the first string the time should remain the same when converted to UTC, as Daylight saving time (DST) is not used in November.
Whereas the time from the second string should change to 1 hour earlier when converted to UTC, as DST is used in early October.
I would like to convert both of these strings with moment.js and moment-timezone.js
So far, I've tried the below without success, any suggestions?
var format = 'D MMMM Y HH:mm';
console.log(
"First momement() call should return value with 09:58 and next one with 08:58': ",'\n',
moment("2019-11-01 09:58", 'YYYY-MM-DD HH:mm').tz('GMT').utc().format(format),'\n',
moment("2019-10-01 09:58", 'YYYY-MM-DD HH:mm').tz('GMT').utc().format(format)
);
console.log(
"First momement() call should return value with 09:58 and next one with 08:58': ",'\n',
moment.tz("2019-11-01 09:58", 'YYYY-MM-DD HH:mm',"GMT").utc().format(format),'\n',
moment.tz("2019-10-01 09:58", 'YYYY-MM-DD HH:mm',"GMT").utc().format(format)
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.5/moment-timezone-with-data-2010-2020.min.js"></script>