/* Reference: https://www.epochconverter.com/programming/#javascript */
//Convert human readable dates to epoch
var myDate = new Date( 1533132667*1000);
document.write(myDate.toGMTString()+"<hr>"+myDate.toUTCString()+"<hr>"+myDate.toLocaleString());
document.write("<hr/>");
/* document.write(convertEpochToSpecificTimezone(5.30)) */
//Convert human readable dates to epoch:
var myDate = new Date("Wed Aug 01 2018 14:11:07 GMT");
var myEpoch = myDate.getTime()/1000.0;
document.write(myEpoch);
function convertEpochToLocalDateTime(dt) {
var sourceEpoch = parseInt(dt);
if (isNaN(sourceEpoch)) {
// console.log('Invalid Timestamp');
} else {
if (sourceEpoch <= 9999999999) {
sourceEpoch *= 1000;
}
// console.log(new Date(sourceEpoch));
var options = { hour12: false };
var date = new Date(sourceEpoch);
// console.log(date.toLocaleString("en-US", options));
//return new Date(sourceEpoch);
return date.toGMTString("en-US", options);
}
}
document.write("<hr/>");
document.write(convertEpochToLocalDateTime(1533132667));
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.