Q:

How to Convert UTC Date Time to Local Date Time in JavaScript

0

How to Convert UTC Date Time to Local Date Time in JavaScript

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the toString() Method

You can simply use the toString() method to convert UTC or GMT date time to local date time in JavaScript. Greenwich Mean Time (GMT) is a time zone and Coordinated Universal Time (UTC) is a time standard. Although GMT and UTC share the same current time in practice.

Let's try out the following example to understand how this method actually works:

<script>
    // Create date object from datetime string
    var date = new Date('Tue, 21 Apr 2020 09:20:30 GMT');
    
    // Coverting to local datetime 
    console.log(date.toString());
    
    // Coverting local datetime back to UTC
    console.log(date.toUTCString()); // Tue, 21 Apr 2020 09:20:30 GMT
</script>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Load Local JSON File Using jQuery... >>
<< How to Set Value of Textarea in jQuery...