-1

my response from the service always give me answer in INDIAN date and time I want my webpage to access user timezone and give date and time according to that:: {msg_date: " 15-03-2021 13:06:29", msg_query_id: "1", msg_query_type: "C", msg_ref_type: "REPLY",…}

I want to convert the res['msg_date'] according to the users location

deeksha
  • 11
  • 1
  • Does this answer your question? [Convert UTC date time to local date time](https://stackoverflow.com/questions/6525538/convert-utc-date-time-to-local-date-time) – Alexey Nikonov Mar 15 '21 at 12:00
  • Use moment to create a Date object by providing it the datetime + timezone values. After that format the date object in browser's timezone to display at UI. Or, store datetime at backend in UTC, that will be simpler to understand. And, it would be easy if backend returns the datetime in ISO format. – Ajeet Shah Mar 15 '21 at 12:56

1 Answers1

0

try :

let date = new Date().toUTCString();
console.log("UTC Date: " + date);

let localDate = moment(date).local(true).format("YYYY-MM-DD HH:mm:ss");
console.log("Moment Local Date: " + localDate); // Moment Local Date: 2021-03-15