1

in my database one column has utcdatetime value and i want show that date time in the timezone of the country.

this is my database value: 2020-02-25 11:12:28 PM and i want output a value for example us system: 2020-02-25 1:12:28 PM approximately because India is 10 hours and 30 minutes ahead of Washington, DC, USA

i tried with the code below:

 function GridCreated(sender, args) {
            var masterTable = $find("<%= dgAdminErrorLog.ClientID %>").get_masterTableView();
        var items = masterTable.get_dataItems();

        for (var i = 0; i < items.length; i++) {
            var date = masterTable.getCellByColumnUniqueName(items[i], "ErrorDateTimeUtc").innerHTML;
             // conver the date and set it back to the cell.
            var d = new Date();
            var systimezone = d.getTimezone();
            var indiaTime = date.toLocaleString("en-US", { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone});
           masterTable.getCellByColumnUniqueName(items[i], "ErrorDateTimeUtc").innerHTML = indiaTime.toLocaleString();

        }
    }
Mahatmasamatman
  • 1,537
  • 2
  • 6
  • 20
Queen
  • 39
  • 3
  • Does [Convert UTC date time to local date time](https://stackoverflow.com/q/6525538/1115360) give you any useful ideas? – Andrew Morton Feb 25 '20 at 11:50

1 Answers1

2
var usaTime = new Date().toLocaleString("en-US", {
  timeZone: "America/New_York"
});
usaTime = new Date(usaTime);
console.log("USA time: " + usaTime.toLocaleString());
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
Justin
  • 131
  • 2
  • 12