简体   繁体   中英

How to convert epoch timestamp to normal date time format using JavaScript?

Epoch Time Stamp:

1598944721950

Output Required:

dd/mm/yyy hh:mm AM/PM

 const epochToFullDateTime = (epochValue) => { let dateObject = new Date(epochValue); let timeStamp = dateObject.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", }); const ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(dateObject); const mo = new Intl.DateTimeFormat("en", { month: "numeric" }).format(dateObject); const da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(dateObject); let fullDateTime = `${da}/${mo}/${ye} ${timeStamp}`; return fullDateTime; }; let time = epochToFullDateTime(1598944721950); console.log(time);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM