-->

How to get the current date and time - JavaScript with JavaScript - HOSTVN Blog

    JavaScript is the programming language used for the World Wide Web. Date Object in JavaScript Very useful for checking the date and time visitors come to your site. This tutorial will help you know how to use JavaScript to get the current Date Time from the client.

    Create Date Object in JavaScript

    To create a Date Object with the current date and time, add the variable today to your js file:

    Use the Get Method to display the current Date in JavaScript

    If you want to get dates in the format DD-MM-YYY, you need to add the following variable:

    • today.getFullYear () - Display the year with 4 digits.
    • today.getMonth () + 1 - Display month.
    • today.getDate () - Display the date.

    current date

    If you prefer a different format, just change the order of the commands.

    Display hours, minutes and seconds with JavaScript

    To display the time in HH: MM: SS format, edit your file as follows:

    • today.getHours () - Display hours.
    • today.getMinutes () - Display minutes.
    • today.getSeconds () - Display seconds.

    get time - current date and time

    Display the current date and time in JavaScript

    Combine two code segments to display the full date and time in DD-MM-YYY and HH: MM: SS format. Edit your file as follows:

    current date and time

    Conclude

    Through this article we have shown you how to get the current date and time - current Date Time in javascript. If you have any contributions you can leave a comment below. You may also want to view our other shared posts here

    Không có nhận xét nào