let unix_timestamp = 1549312452;
// Create a new JavaScript Date object based on the timestamp
// multiplied by 1000 so that the argument is in milliseconds, not seconds
var date = new Date(unix_timestamp * 1000);
// Hours part from the timestamp
var hours = date.getHours();
// Minutes part from the timestamp
var minutes = "0" + date.getMinutes();
// Seconds part from the timestamp
var seconds = "0" + date.getSeconds();
// Will display time in 10:30:23 format
var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
console.log(formattedTime);
For more information regarding the Date object, please refer to MDN or the ECMAScript 5 specification.
Answer from Aron Rotteveel on Stack Overflow Top answer 1 of 16
2366
let unix_timestamp = 1549312452;
// Create a new JavaScript Date object based on the timestamp
// multiplied by 1000 so that the argument is in milliseconds, not seconds
var date = new Date(unix_timestamp * 1000);
// Hours part from the timestamp
var hours = date.getHours();
// Minutes part from the timestamp
var minutes = "0" + date.getMinutes();
// Seconds part from the timestamp
var seconds = "0" + date.getSeconds();
// Will display time in 10:30:23 format
var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
console.log(formattedTime);
For more information regarding the Date object, please refer to MDN or the ECMAScript 5 specification.
2 of 16
383
function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
return time;
}
console.log(timeConverter(0));
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › now
Date.now() - JavaScript | MDN
// This example takes 2 seconds to run const start = Date.now(); console.log("starting timer..."); // Expected output: "starting timer..." setTimeout(() => { const ms = Date.now() - start; console.log(`seconds elapsed = ${Math.floor(ms / 1000)}`); // Expected output: "seconds elapsed = 2" }, ...
javascript - How to convert date to timestamp? - Stack Overflow
3 Convert date time to integer timestamp in javascript More on stackoverflow.com
How to REALLY get a UTC Date object
var date = new Date('2015-10-11T14:03:19.243Z'); var str = date.toISOString();
More on reddit.comHow to get timestamp from firestore in react-native
Use the toDate() method provided by firebase to convert firebase timestamps to JavaScript Date Objects More on reddit.com
any way to include timestamps in logs?
Help > Options More on reddit.com
Videos
03:14
How to Convert Timestamp to Date Format in Javascript - YouTube
07:37
How To Convert Firestore Timestamp To JavaScript Date - YouTube
03:43
How to Convert Unix Timestamp to Universal Time in Javascript - ...
18:06
52. Generating and Retrieving Firestore Timestamp to auto populate ...
04:31
Timestamps, Date.now( ) and valueOf( ) - YouTube
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › parse
Date.parse() - JavaScript | MDN
The Date.parse() static method parses a string representation of a date, and returns the date's timestamp. // Standard date-time string format const unixTimeZero = Date.parse("1970-01-01T00:00:00Z"); // Non-standard format resembling toUTCString() const javaScriptRelease = Date.parse("04 Dec ...
Stack Abuse
stackabuse.com › bytes › how-to-convert-a-date-to-timestamp-in-javascript
How to Convert a Date to Timestamp in JavaScript
October 4, 2023 - It'll be a similar process as before, but with the extra step of converting the string to a Date object and then the timestamp. Just make sure your date string is in a format that the Date constructor can understand. According to MDN: The JavaScript specification only specifies one format to be universally supported: the date time string format, a simplification of the ISO 8601 calendar date extended format.
W3Schools
w3schools.com › jsref › jsref_obj_date.asp
JavaScript Date Reference
altKey (Mouse) altKey (Key) animationName bubbles button buttons cancelable charCode clientX clientY code ctrlKey (Mouse) ctrlKey (Key) currentTarget data defaultPrevented deltaX deltaY deltaZ deltaMode detail elapsedTime elapsedTime eventPhase inputType isTrusted key keyCode location metaKey (Mouse) metaKey (Key) newURL oldURL offsetX offsetY pageX pageY persisted propertyName relatedTarget relatedTarget screenX screenY shiftKey (Mouse) shiftKey (Key) target targetTouches timeStamp touches type which (Mouse) which (Key) view HTML Event Methods
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Date Methods
The getDay() method returns the weekday of a date as a number (0-6). In JavaScript, the first day of the week (day 0) is Sunday. Some countries in the world consider the first day of the week to be Monday.
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
Create a Date object with the time equal to number of milliseconds (1/1000 of a second) passed after the Jan 1st of 1970 UTC+0. // 0 means 01.01.1970 UTC+0 let Jan01_1970 = new Date(0); alert( Jan01_1970 ); // now add 24 hours, get 02.01.1970 UTC+0 let Jan02_1970 = new Date(24 * 3600 * 1000); alert( Jan02_1970 ); An integer number representing the number of milliseconds that has passed since the beginning of 1970 is called a timestamp.
Timestamp Converter
timestamp.online
Timestamp Converter
Convert timestamp to date or date to timestamp easily. Learn how to convert timestamp to date in Python, PHP, JavaScript, Bash, ...
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). This timestamp is timezone-agnostic and uniquely defines an instant in history.
Top answer 1 of 16
321
Split the string into its parts and provide them directly to the Date constructor:
Update:
var myDate = "26-02-2012";
myDate = myDate.split("-");
var newDate = new Date( myDate[2], myDate[1] - 1, myDate[0]);
console.log(newDate.getTime());
Updated: Also, you can use a regular expression to split the string, for example:
const dtStr = "26/02/2012";
const [d, m, y] = dtStr.split(/-|\//); // splits "26-02-2012" or "26/02/2012"
const date = new Date(y, m - 1, d);
console.log(date.getTime());
2 of 16
100
Try this function, it uses the Date.parse() method and doesn't require any custom logic:
function toTimestamp(strDate){
var datum = Date.parse(strDate);
return datum/1000;
}
alert(toTimestamp('02/13/2009 23:31:30'));
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getTime
Date.prototype.getTime() - JavaScript | MDN
July 10, 2025 - const moonLanding = new Date("July 20, 69 20:17:40 GMT+00:00"); // Milliseconds since Jan 1, 1970, 00:00:00.000 GMT console.log(moonLanding.getTime()); // Expected output: -14182940000 ... A number representing the timestamp, in milliseconds, of this date.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › UTC
Date.UTC() - JavaScript | MDN
Integer value representing the millisecond segment of a time. Defaults to 0. A number representing the timestamp of the given date.