Tried multiple methods to convert the local time to UTC. Tried Offset(420) as the time difference is UTC 7 and it worked. So here what i need is my users will be giving a request from different timezones and all of them should convert to UTC. So when giving time from different timezone the UTC time difference will also change how it can be identified and change accordingly. how can i do that?
Asked
Active
Viewed 68 times
1
-
Does this answer your question? [convert local timezone timestamp to UTC timestamp](https://stackoverflow.com/questions/52647864/convert-local-timezone-timestamp-to-utc-timestamp) – Avani Khabiya Apr 28 '21 at 14:46
1 Answers
0
You can use moment.utc() to get UTC time. If you wish to send it to the server, it's probably best to send as an ISO-8601 date string.
const localDate = moment();
const utcDate = moment.utc();
console.log("Local time:", localDate.format("YYYY-MM-DD HH:mm:ss"));
console.log("UTC time:", utcDate.format("YYYY-MM-DD HH:mm:ss"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

Terry Lennox
- 29,471
- 5
- 28
- 40