Convert UTC Date Time to Local Date Time

by Katheer Mizal

HTML

<input type="datetime-local" className="datetime-input"value='2017-06-01T08:30'>

JavaScript

var dateControl = document.querySelector('input[type="datetime-local"]');

// Create date object from datetime string
var date = new Date(dateControl.value);

// Coverting local datetime back to UTC
console.log(date.toUTCString()); // Output "Tue, 26 Oct 2021 01:14:27 GMT"

// Coverting to local datetime 
console.log(date.toString());  // Output "Tue Oct 26 2021 06:44:27 GMT+0530 (India Standard Time)"

// Coverting to local timezone 
console.log(date.toLocaleString()); // Output "10/26/2021, 6:44:27 AM"

// Convert localtime using ISO
console.log(date.toISOString()); // Output "2017-06-01T03:00:00.000Z"