Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Convert Unix Timestamp to JavaScript Time</title> </head> <body> <script> // Timestamp in seconds var unixTimestamp = 1651822834; /* Create a new JavaScript Date object based on Unix timestamp. Multiplied it by 1000 to convert it into milliseconds */ var date = new Date(unixTimestamp * 1000); // Generate date string document.write(date.toLocaleDateString("en-US") + "<br>"); // Prints: 5/6/2022 document.write(date.toLocaleDateString("en-GB") + "<br>"); // Prints: 06/05/2022 document.write(date.toLocaleDateString("default") + "<br>"); // Prints: 5/6/2022 // Generate time string document.write(date.toLocaleTimeString("en-US") + "<br>"); // Prints: 1:10:34 PM document.write(date.toLocaleTimeString("it-IT") + "<br>"); // Prints: 13:10:34 document.write(date.toLocaleTimeString("default")); // Prints: 1:10:34 PM </script> </body> </html>