Level 104
You are missing the locale. Just use toLocaleString("en-US") as this will have both the date and time parts
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have time: 1614358672 How do I convert it to this kind of time: 2/26/2021, 11:57:52 PM
this is my code but it not working
let date = new Date(1614358672)
console.log(date.toLocaleDateString() + ', ' + date.toLocaleTimeString())
Sorry, I was focused on the formatting and didn't notice how you instantiated the Date. You must multiply the Unix timestamp by 1000 because in Javascript the timestamps are in milli-seconds
let date = new Date(1614358672 * 1000)
console.log(date.toLocaleString('en-US', { timeZone: 'America/New_York' }))
Edit pass the required timezone in the second argument
Please or to participate in this conversation.