timestamp to date javascript – How To Convert Timestamp To Date and Time in JavaScript?

timestamp to date javascript : How To Convert Timestamp To Date and Time in JavaScript : Javascript however supports multiple functions to present date as well as time in human readable form. like as toDateString(), toGMTString(), toISOString(), toJSON(), toLocaleDateString(), toLocaleTimeString(), toLocaleString(), toString(), toTimeString(), and toUTCString().

timestamp to date javascript | Convert Timestamp to Date in JavaScript

Convert the unix timestamp into milliseconds by multiplying it by 1000. JavaScript Converting milliseconds to date

var timestamp = 1607110465663
var current_dt = new Date(timestamp);
console.log(current_dt.getTime())
console.log(current_dt)

Function to convert timestamp to human date in javascript

var d = new Date(1382086394000);

The Date class supports many functions to represent the Date in the preferred format like:

  1. getDate() returns the day of the calendar month 1 to 31 at that time.
  2. getMonth() returns the month number 0 to 11 at that time.
  3. getFullYear() returns the year in 4-digits format.
  4. getHours() returns the exact hour in 24-hour format for that time.
  5. getMinutes() returns the exact minutes 0 to 59 at that time.
  6. getSeconds() returns the exact seconds 0 to 59 at that time.

Example : timestamp to date javascript

var timestamp = 1607110465663
var current_dt = new Date(timestamp);

console.log("Your Join Date: "+current_dt.getDate()+
          "/"+(current_dt.getMonth()+1)+
          "/"+current_dt.getFullYear()+
          " "+current_dt.getHours()+
          ":"+current_dt.getMinutes()+
          ":"+current_dt.getSeconds());

Result:

Your Join Date: 4/12/2020 19:34:25

The following timestamp to date javascript example demonstrates how we can convert the Unix timestamp to JavaScript Date timestamp.

var currentTimesTmpUnix = 62678980
var current_dt = new Date(currentTimesTmpUnix*1000);
console.log("Unix Timestamp:",currentTimesTmpUnix)
console.log("Your Join Date Timestamp:",current_dt.getTime())
console.log(current_dt)
console.log("Your Join Date: "+current_dt.getDate()+
          "/"+(current_dt.getMonth()+1)+
          "/"+current_dt.getFullYear()+
          " "+current_dt.getHours()+
          ":"+current_dt.getMinutes()+
          ":"+current_dt.getSeconds());

Results:

Unix Timestamp: 62678980
Your Join Date Timestamp: 62678980000
Mon Dec 27 1971 12:49:40 GMT+0200 (Eastern European Standard Time)
Your Join Date: 27/12/1971 12:49:40

Don’t Miss : Convert date to unix timestamp JavaScript

Convert the Unix Timestamp to Milliseconds

const currentTimesTmpUnix = 1575909015

const milliseconds = currentTimesTmpUnix * 1000 // 1575909015000

Create a Date Object Using new Date()

const currentTimesTmpUnix = 1575909015

const milliseconds = 1575909015 * 1000 // 1575909015000

const getDateInfo = new Date(milliseconds)

Create Human-Friendly Date Strings With .toLocaleString()

const currentTimesTmpUnix = 1575909015

const milliseconds = 1575909015 * 1000 // 1575909015000

const getDateInfo = new Date(milliseconds)

const humanDateFormat = getDateInfo.toLocaleString() //2022-12-9 10:30:15

Don’t Miss : How to convert unix timestamp string to readable date in JavaScript?

const currentTimesTmpUnix = 1575909015

const milliseconds = 1575909015 * 1000 // 1575909015000

const getDateInfo = new Date(milliseconds)

const humanDateFormat = getDateInfo.toLocaleString() //2022-12-9 10:30:15

getDateInfo.toLocaleString("en-US", {weekday: "long"}) // Monday
getDateInfo.toLocaleString("en-US", {month: "long"}) // December
getDateInfo.toLocaleString("en-US", {day: "numeric"}) // 9
getDateInfo.toLocaleString("en-US", {year: "numeric"}) // 2022
getDateInfo.toLocaleString("en-US", {hour: "numeric"}) // 10 AM
getDateInfo.toLocaleString("en-US", {minute: "numeric"}) // 30
getDateInfo.toLocaleString("en-US", {second: "numeric"}) // 15
getDateInfo.toLocaleString("en-US", {timeZoneName: "short"}) // 12/9/2022, 10:30:15 AM CST

I hope you get an idea about timestamp to date javascript.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment