Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Learn JS Date Formats



JavaScript Date Formats


JavaScript provides several ways to work with dates and times, including various date formats. Here are some common date formats in JavaScript:

  1. ISO Date Format: This is a simplified version of the ISO 8601 standard. It follows the pattern YYYY-MM-DD, where:

    • YYYY represents the year (4 digits)
    • MM represents the month (2 digits, 01-12)
    • DD represents the day (2 digits, 01-31)
  2. let isoDate = new Date('2024-04-21');


  3. Long Date Format: This format includes the full name of the weekday, month, day, and year. For example: April 21, 2024.

  4. let longDate = new Date().toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });


  5. Short Date Format: This format includes the numeric representation of the month, day, and year. For example: 4/21/2024.

  6. let shortDate = new Date().toLocaleDateString('en-US');


  7. Time Format: This format represents the time using hours, minutes, seconds, and optionally milliseconds. For example: 12:30:45.

  8. let time = new Date().toLocaleTimeString('en-US');


  9. DateTime Format: This format combines both the date and time components. For example: 4/21/2024, 12:30:45 PM.

  10. let dateTime = new Date().toLocaleString('en-US');


  11. Custom Format: You can also create custom date formats using various methods like getFullYear(), getMonth(), getDate(), getHours(), getMinutes(), getSeconds(), etc., and concatenate the values as needed.

  12. let customFormat = `${new Date().getFullYear()}-${(new Date().getMonth() + 1).toString().padStart(2, '0')}-${new Date().getDate().toString().padStart(2, '0')}`;


    These are just a few examples of how you can format dates in JavaScript. Depending on your requirements, you may need to use different methods and libraries to achieve specific date formatting needs.





Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java