'How to convert current datetime into given timezone and store in MongoDB & fetch in DD-MM-YYYY HH:mm format?
My local time is 'Asia/Kolkata.'
And I have to convert the current DateTime into 'Pacific/Auckland'
and store it into MongoDB
And on fetch I have to format this date into DD-MM-YYYY HH:mm
Solution 1:[1]
Firstly,
To store into the database, I prefer storing in UTC mode.
In case you need to convert your time into some other timezone's time, Have a look at it here.
date = new Date();
timeZone = 'Pacific/Auckland';
timestamp = date.toLocaleString('en-US', { timeZone })
Hope this works!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sachin |