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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
In essence, the timezone offset is the offset from UTC time, at the time represented by the Date object and at the location of the host environment. There are two groups of Date methods: one group gets and sets various date components by interpreting the timestamp as a local time, while the other uses UTC.
🌐
InfluxData
influxdata.com › home › how to get, convert & format javascript date from timestamp | influxdata
How to Get, Convert & Format JavaScript Date From Timestamp | InfluxData
February 10, 2023 - Once installed, we can use its API to format dates in various ways. const moment = require('moment'); const timestamp = 1616608200000; // example timestamp const formattedDate = moment(timestamp).format('dddd, MMMM Do YYYY'); console.log(fo...
🌐
CoreUI
coreui.io › answers › how-to-convert-a-timestamp-to-a-date-in-javascript
How to convert a timestamp to a date in JavaScript · CoreUI
October 2, 2025 - Convert a timestamp to a date in JavaScript using new Date() constructor with timestamp parameter for accurate date object creation.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
The call to Date.parse(str) parses the string in the given format and returns the timestamp (number of milliseconds from 1 Jan 1970 UTC+0).
🌐
Codedamn
codedamn.com › news › javascript
How to convert timestamp to date in JavaScript?
November 3, 2022 - Convert a timestamp to a valid date object using moment.js. We may format the generated date by chaining the format() method. It accepts a string, containing the date format, as an argument.
🌐
Sentry
sentry.io › sentry answers › javascript › convert unix timestamp to date and time in javascript
Convert Unix timestamp to date and time in JavaScript | Sentry
const myUnixTimestamp = 1691622800; // start with a Unix timestamp const myDate = new Date(myUnixTimestamp * 1000); // convert timestamp to milliseconds and construct Date object console.log(myDate); // will print "Thu Aug 10 2023 01:13:20" followed by the local timezone on browser console · As shown above, printing out a Date object will show its date and time in a standard, human-readable format.
🌐
Toptal
toptal.com › developers › software › definitive-guide-to-datetime-manipulation
The Definitive Guide to DateTime Manipulation
December 2, 2020 - It offers convenient methods to get the current time in JavaScript, store a date in a variable, perform date arithmetic, and format the date based on the user’s locale. Due to differences between browser implementations and incorrect handling of Daylight Savings Time (DST), depending on the Date object for mission-critical applications is not recommended and you should probably be using a DateTime library like Luxon, date-fns, or dayjs. (Whatever you use, avoid the once-popular Moment.js—often simply called moment, as it appears in code—since it’s now deprecated.)
Find elsewhere
Top answer
1 of 8
127

getDay() returns the day of the week. To get the date, use date.getDate(). getMonth() retrieves the month, but month is zero based, so using getMonth() + 1 should give you the right month. Time value seems to be ok here, albeit the hour is 23 here (GMT+1). If you want universal values, add UTC to the methods (e.g. date.getUTCFullYear(), date.getUTCHours())

const timestamp = 1301090400;
const date = new Date(timestamp * 1000);
const datevalues = [
   date.getFullYear(),
   date.getMonth()+1,
   date.getDate(),
   date.getHours(),
   date.getMinutes(),
   date.getSeconds(),
];
alert(datevalues); //=> [2011, 3, 25, 23, 0, 0]

Here is a small helper idea to retrieve values of a given Date:

const dateHelper = dateHelperFactory();
const formatMe = date => {
  const vals = `yyyy,mm,dd,hh,mmi,ss,mms`.split(`,`);
  const myDate = dateHelper(date).toArr(...vals);
  return `${myDate.slice(0, 3).join(`/`)} ${
    myDate.slice(3, 6).join(`:`)}.${
    myDate.slice(-1)[0]}`;
};

// to a formatted date with zero padded values
console.log(formatMe(new Date(1301090400 * 1000)));

// the raw values
console.log(dateHelper(new Date(1301090400 * 1000)).values);

function dateHelperFactory() {
  const padZero = (val, len = 2) => `${val}`.padStart(len, `0`);
  const setValues = date => {
    let vals = {
       yyyy: date.getFullYear(),
       m: date.getMonth()+1,
       d: date.getDate(),
       h: date.getHours(),
       mi: date.getMinutes(),
       s: date.getSeconds(),
       ms: date.getMilliseconds(), };
    Object.keys(vals).filter(k => k !== `yyyy`).forEach(k => 
      vals[k[0]+k] = padZero(vals[k], k === `ms` && 3 || 2) );
    return vals;
  };
  
  return date => ( {
    values: setValues(date),
    toArr(...items) { return items.map(i => this.values[i]); },
  } );
}
.as-console-wrapper {
    max-height: 100% !important;
}

Or see this small stackblitz project (a little bit more efficient).

2 of 8
78
var newDate = new Date();
newDate.setTime(unixtime*1000);
dateString = newDate.toUTCString();

Where unixtime is the time returned by your sql db. Here is a fiddle if it helps.

For example, using it for the current time:

document.write( new Date().toUTCString() );

🌐
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 1995 00:12:00 GMT"); console.log(unixTimeZero); // Expected output: 0 console.log(javaScriptRelease); // Expected output: 818035920000
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
W3Schools.com
In other words: If a date/time is created in GMT (Greenwich Mean Time), the date/time will be converted to CDT (Central US Daylight Time) if a user browses from central US. Short dates are written with an "MM/DD/YYYY" syntax like this: const d = new Date("03/25/2015"); Try it Yourself » · In some browsers, months or days with no leading zeroes may produce an error: ... The behavior of "YYYY/MM/DD" is undefined. Some browsers will try to guess the format.
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - The JavaScript Date Object allows you to manipulate, format, and compare JavaScript dates and times. It is used for converting between Date JS objects and epoch timestamps and performing other advanced operations​.
🌐
Scaler
scaler.com › home › topics › convert timestamp to date in javascript
Convert Timestamp to Date in JavaScript - Scaler Topics
October 13, 2022 - The UNIX timestamps can be converted to the required date and time formats by using the Date() object and its methods in JavaScript.
🌐
Reddit
reddit.com › r/ionic › format timestamp to readable date or words
r/ionic on Reddit: Format Timestamp to readable date or words
April 19, 2023 -

Hello,

I'm trying to find a way to convert a Timestamp (in seconds) to something like depending of the current date :

  • 03/04/2014 at 8:30pm

  • Tomorrow at 8:30pm

  • Today at 8:30pm

I think I heard about it from Ionic Academy, but since it's not English native speaker, I cannot understand how you call this process and cannot find bacn information about it.

Could you help?

Thank you.

🌐
freeCodeCamp
freecodecamp.org › news › how-to-format-a-date-with-javascript-date-formatting-in-js
How to Format a Date with JavaScript – Date Formatting in JS
November 7, 2024 - Apart from formatting dates for display, it's essential to handle user input for dates effectively. Here are a few considerations: Parsing User Input: Use the Date.parse() method or external libraries like Moment.js or Luxon to parse user-provided dates into valid Date objects.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Representing_dates_times
Representing dates & times - JavaScript | MDN
JavaScript handles dates similarly to Java. The two languages have many of the same date methods, and both languages store dates as the number of milliseconds since midnight at the beginning of January 1, 1970, UTC, with a Unix Timestamp being the number of seconds since the same instant.
🌐
Toptal
toptal.com › software › definitive-guide-to-datetime-manipulation
How to get the Timestamp And Date in Javascript
December 2, 2020 - It offers convenient methods to get the current time in JavaScript, store a date in a variable, perform date arithmetic, and format the date based on the user’s locale. Due to differences between browser implementations and incorrect handling of Daylight Savings Time (DST), depending on the Date object for mission-critical applications is not recommended and you should probably be using a DateTime library like Luxon, date-fns, or dayjs. (Whatever you use, avoid the once-popular Moment.js—often simply called moment, as it appears in code—since it’s now deprecated.)
🌐
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 - Note: The getTime() method returns the timestamp in milliseconds. If you need the timestamp in seconds, you can divide the result by 1000. So what if we have a date in string format?
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-a-date-string-to-timestamp-in-javascript
How to Convert a Date String to Timestamp in JavaScript ? | GeeksforGeeks
April 28, 2025 - ... Example: In this example, we are using the above-explained method. ... In this approach, using new Date() creates a date object from a string, then .getTime() extracts the Unix timestamp (milliseconds since 1970).
🌐
Linux Hint
linuxhint.com › convert-timestamp-to-date-format-javascript
How to Convert Timestamp to Date Format in JavaScript
November 11, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use