We have to build a website for our client that runs Angular 9+ in the front end and nodejs is the server backend application. Everything working good.
Now, my client wants to support customers initially from the following timezones: Indian Time, Pacific Time, Arizona Time, Mountain Time, Central Time and Eastern Time. We are planning to use @js-joda/core and @js-joda/timezone to accomplish the job.
One of the requirements is to validate the date entered by the user. The date must belong to the current month only. The server is set with UTC timezone. We are thinking about converting the datetime to UTC and then storing it in the (mongodb) database. But we are not sure how we can convert the given date to UTC using js-Joda. We tried using the following code but it doesn't seem to convert.
var jsJoda = require("@js-joda/core");
require("@js-joda/timezone");
var indiaZone = jsJoda.ZoneId.of("Asia/Calcutta");
var localDateTime = jsJoda.LocalDateTime.parse("2021-10-05T23:18:09.905");**//<--user entry date**
var localTime = jsJoda.ZonedDateTime.of(localDateTime, indiaZone);
var utcZoned = jsJoda.ZonedDateTime.of(localTime, jsJoda.ZoneOffset.UTC);
console.log('Current Time in UTC: ' + utcZoned.toString());
I expected the date printed would be 5.5 hrs behind but it didn't. Can you please assist if I'm in the right direction and also why the UTC time is showing the same time passed?
My issue was that I had a string in eastern standard time that I needed to be converted to UTC using jsJoda.
Solution:
LocalDate { _year: 2021, _month: 5, _day: 22 }
,LocalTime { _hour: 2, _minute: 0, _second: 0, _nano: 0 }