JavaScript Program to Display Date and Time Last Updated : 11 Sep, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to Display Date and Time in JavaScript. Displaying the time and date can be useful when you want to know the time and date. And also if you want to use them in the app. These are the following approaches which are used in JavaScript for Date and Time: Using the Date() ConstructorUsing the Date.now() MethodUsing the Date() ConstructorThis approach creates a new instance of the Date object using its constructor. It provides various methods to extract different components of the date and time. Syntax:const variable_name= new Date();Example: JavaScript // Creating object of // Date constructor const currentDate = new Date(); // Extract components of the date and time // Getting year: 2023 const year = currentDate.getFullYear(); // Getting month const month = currentDate.getMonth() + 1; // Getting day const day = currentDate.getDate(); // Getting hours const hours = currentDate.getHours(); // Getting minutes const minutes = currentDate.getMinutes(); // Getting seconds const seconds = currentDate.getSeconds(); // Using template literal for // printing the date and time // in console console.log(`Current Date: ${year}-${month}-${day}`); console.log(`Current Time: ${hours}:${minutes}:${seconds}`); OutputCurrent Date: 2023-9-5 Current Time: 6:41:6Using the Date.now() MethodThis method returns the current timestamp in milliseconds since the Unix epoch (January 1, 1970). It can be converted into a readable date and time format. Syntax:const timestamp = Date.now();Example: JavaScript const timestamp = Date.now(); // Convert timestamp to a readable date and time format const currentDate = new Date(timestamp); // Formatting date const formattedDate = currentDate.toLocaleString(); // Printing Date and Time // in console console.log(`Current Date and Time: ${formattedDate}`); OutputCurrent Date and Time: 9/5/2023, 6:51:59 AM Comment More infoAdvertise with us Next Article JavaScript Program to Display Date and Time N nikhilgarg527 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Program Similar Reads Java Program to Display Current Date and Time Java is a most powerful programming language, by which we can do many things and Java is an industry preferable language. So it has a huge field of features. Here we discuss one of the best features of Java, that is how to represent the current date and time using Java. There are many ways to do thi 3 min read C# Program to Display Date in String System namespace and mscorlib.dll assembly in C# language provide a variety of classes and structures. It also provides DateTime struct using which we can initialize Data and Time objects. Using this struct we can also determine the year, month, weekday, etc. 1. DateTime Constructor: DateTime constr 7 min read Java Program to Convert TimeStamp to Date Date Time class is used to display date and time and manipulate date and time in java and in addition to this it is also used for formatting date and time class in java across time zone associated data. So in order to import this class from a package called java.utils Timestamp class can be converte 3 min read Print current day and time using HTML and JavaScript Printing the current day and time using HTML and JavaScript involves dynamically displaying the present date and time on a webpage. JavaScript's Date object is used to retrieve the current day, month, year, and time, which is then embedded in the HTML content.Approach:Retrieve Current Date and Day: 2 min read Java Program to Convert Date to String The date type object can be converted to a string in Java using a large variety of in-built classes available in Java. Given a date, we need to convert the date to a given format of the string. Examples: Input: date = â2020-11-13âOutput: 2020-11-13 Input: date = â2020-12-14âOutput: 2020-12-14 Method 3 min read Java Program to Get Today's Date Java is the most powerful programming language, by which we can perform many tasks and Java is an industry preferable language. So it is filled with a huge amount of features. Here we are going to discuss one of the best features of Java, which is how to get today's or current date using Java. Metho 2 min read Java Program to Print the Months in Different Formats For printing months in different formats, we are going to use two classes of java.util package. That is the first one Calendar class and another one is Formatter class. From Calendar class use getInstance() method to get instance (time and date information) of calendar according to the current time 2 min read Java Program Format Time in MMMM Format In Java, The MMM format for months is a short form of the month using 3 characters. SimpleDateFormat class is used for implementing this format in java and you can import this package by using the following code. import java.text.SimpleDateFormat Example: Months Name(MMMM Format)MMM FormatJanuaryJan 2 min read How to Add Time to Date in Java? In Java, You can add the time to a Date object and it can be part of the java.util.Calendar package and another approach be used to newer java.time package. I can explain both approaches adding the time to a Date in Java programming. In this article, we are going to learn, how to add time to date in 3 min read Shell Script to Display Time in Word Linux/Unix has the inbuilt functionality to show the current time. Usually, Linux shows the current time in general format rather than word, and with this may some user can disagree. So, To show the current time in a better and pretty format here is given a bash script. It shows the current time in 3 min read Like