Transforming a 10-digit Timestamp into a Readable Date
Deciphering a 10-digit timestamp can be perplexing. Encountered this value in a JSON API response instead of the expected date format. Initially puzzled on how to convert it for UI display, I later discovered that these 10-digit timestamps represent seconds.
Enough with the history lesson, now, how can we make it useful in JavaScript?
// Timestamp
const ts = 1504095567183
// Native
new Date(ts)
// Moment.js
moment(ts)
// day.js
dayjs.unix(ts)