I think I have a simpler solution -- set the initial date to the epoch and add UTC units. Say you have a UTC epoch var stored in seconds. How about 1234567890. To convert that to a proper date in the local time zone:
var utcSeconds = 1234567890;
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(utcSeconds);
d is now a date (in my time zone) set to Fri Feb 13 2009 18:31:30 GMT-0500 (EST)
Top answer 1 of 16
690
I think I have a simpler solution -- set the initial date to the epoch and add UTC units. Say you have a UTC epoch var stored in seconds. How about 1234567890. To convert that to a proper date in the local time zone:
var utcSeconds = 1234567890;
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(utcSeconds);
d is now a date (in my time zone) set to Fri Feb 13 2009 18:31:30 GMT-0500 (EST)
2 of 16
380
It's easy, new Date() just takes milliseconds, e.g.
new Date(1394104654000)
> Thu Mar 06 2014 06:17:34 GMT-0500 (EST)
Get epoch for a specific date using Javascript - Stack Overflow
This is not a problem if you really want the time since Epoch considering your timezone. So if you want to get time since Epoch for the current Date or even a specified Date based on the computer's timezone, you're free to continue using this method. More on stackoverflow.com
datetime - Javascript Convert Date Time string to Epoch - Stack Overflow
so I give up...been trying to do this all day; I have a string that supplies a date and time in the format dd/MM/yyyy hh:mm (04/12/2012 07:00). I need to turn that into an Epoch date so I can do ... More on stackoverflow.com
Everything you need to know to master dates in JavaScript
Temporal API is Stage 3 now, so should be usable soon. https://github.com/tc39/proposal-temporal More on reddit.com
This can’t be the most efficient way of converting a date to UTC in JavaScript...
Right, some few hundred npm dependencies would do the job better! More on reddit.com
Videos
DEV Community
dev.to › iamephraim › how-to-convert-epoch-timestamp-to-date-using-javascript-352f
How to Convert Epoch Timestamp to Date Using JavaScript - DEV Community
March 24, 2022 - Being a relatively new language that ushered in the use of time in seconds, Solidity provides a global feature called block.timestamp. In this short piece, I explain how you can convert epoch timestamp emitted from your backend solidity contracts into appropriate date that includes day, month, year and time.
Esqsoft
esqsoft.com › javascript_examples › date-to-epoch
Date/Epoch Time Converter - Javascript tools - Learning examples
By making signup date a variable, ... * 3))) { /* ...then this site was signed up more than 3 days ago show them the relevant message */ } 1 Millisecond = 1/1000 in Epoch (used frequently with JavaScript conversions) 1 Second = 1 in Epoch 1 Minute = 60 in Epoch 10 Minutes = ...
Dana Woodman
danawoodman.com › writing › javascript-date-unix-epoc-timestamp
How to convert a JavaScript date to a Unix timestamp (epoch)?
January 31, 2022 - To convert a Unix Timestamp back to a JavaScript date, just multiply it by 1000 to get the number of milliseconds and then pass it to new Date(...): const seconds = 1577865600; const date = new Date(seconds * 1000); A common time format in the world of computer programming is the Unix Timestamp ...
TutorialsPoint
tutorialspoint.com › how-to-convert-epoch-date-to-meaningful-javascript-date
How to convert epoch Date to meaningful JavaScript date?
August 17, 2022 - <html> <head> </head> <body> <h2>Converting epoch date to meaningful JavaScript date.</h2> <h4>Convert milliseconds since epoch to JavaScript Date using the <i>various methods Date class.</i></h4> <p id = "output1"></p> <script> let output1 = document.getElementById("output1"); let milliseconds = 1348755654324; let myDate = new Date(milliseconds); let dateStr = myDate.getFullYear() + "/" + (myDate.getMonth() + 1) + "/" + myDate.getDate() + " " + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds() output1.innerHTML += "date string for " + milliseconds + " milliseconds is : " + dateStr + " <br/> "; </script> </body> </html>
Epoch
epoch101.com › Javascript
Javascript Epoch and DateTime | Epoch101.com
2019-02-16T04:19:44.909Z Year: 2019 Month: 1 Date: 16 Hour: 4 Minutes: 19 Seconds: 44 1995-12-17T03:24:00.000Z · var epoch = 1549505686; var date = new Date(epoch * 1000); console.log(date);
Epoch Converter
epochconverter.com
Epoch Converter - Unix Timestamp Converter
Some browsers use the current DST (Daylight Saving Time) rules for all dates in history. JavaScript does not support leap seconds. ... Epoch converter Batch converter Time zone converter Timestamp list LDAP converter GPS time converter Julian Day converter Chrome/WebKit timestamp Unix hex timestamp Cocoa Core Data timestamp Mac HFS+ timestamp NTP timestamp FAT timestamp SAS timestamp Excel OADate timestamp Seconds/days since year 0 Bin/Oct/Hex converter Year 2038 problem Countdown in seconds Epoch clock
GitHub
github.com › chocolatetoothpaste › epoch
GitHub - chocolatetoothpaste/epoch: epoch.js - Awesome date formatting and calculating for JavaScript
date.from('2012-12-08'); // 1 year ago date.from('2019-12-08'); // in 6 years date.from('2013-12-08 12:34:48'); // less than a minute ago · epoch.leapYear() or epoch.leap() --- true/false if year is leap year
Author chocolatetoothpaste
Top answer 1 of 14
71
var someDate = new Date(dateString);
someDate = someDate.getTime();
2 of 14
51
You can use Date.parse(date).
function epoch (date) {
return Date.parse(date)
}
const dateToday = new Date() // Mon Jun 08 2020 16:47:55 GMT+0800 (China Standard Time)
const timestamp = epoch(dateToday)
console.log(timestamp) // => 1591606075000
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-seconds-since-epoch-in-javascript
How to get seconds since epoch in JavaScript? - GeeksforGeeks
July 12, 2025 - Input: Date = 27-04-2020, 11:55:55 Output: Seconds since epoch - 1587968755 Syntax: new Date(year, month, day, hours, minutes, seconds, milliseconds) Example: ... <script type="text/javascript"> function seconds_since_epoch(d){ return Math.floor( d / 1000 ); } // Driver Code var d = new Date(2020, 4, 29, 22, 00, 00, 00); var sec = seconds_since_epoch(d); document.write("Date " + d + " has " + sec+ " seconds till epoch."); </script> Output:
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
SnapLogic
community.snaplogic.com › snaplogic - integration nation › discussions › getting the most out of the snaplogic platform › designing and running pipelines
Date Epoch Example | SnapLogic - Integration Nation - 19367
February 28, 2017 - SnapLogic uses JavaScript as its scripting language, so the epoch date is internally stored as milliseconds since epoch. In the example below, we are passing in the date in seconds since epoch. 1 - Set a project parameter. In my example, I have “dateEpoch” set to 1472799302.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
A JavaScript date is fundamentally specified as the time in milliseconds that has elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC (equivalent to the UNIX epoch).
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript | MDN
The Date.now() static method returns the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC. // This example takes 2 seconds to run const start = Date.now(); console.log("starting timer..."); // Expected output: "starting ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getTime
Date.prototype.getTime() - JavaScript | MDN
The getTime() method of Date instances returns the number of milliseconds for this date since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.