Javascript Date Methods

Date plays an important role in tracking moments when an event has occurred.

new Date() returns a Date object with current date and time(Ex: Sat Aug 05 2023 13:13:26 GMT+0530 (India Standard Time)).

const d = new Date("2023-03-24");//Date is 2023-03-24

const d = new Date();//

Below are the different kinds of date formats that are accepted(Y-Year;M-Month;D-Date)

  • ISO (YYYY-MM-DD)
    const d = new Date("2024-06-29")
  • Short (MM/DD/YYYY)
    const d=new Date("06/29/2024");
  • Long (MMM DD YYYY )(DD MMM YYYY)
    Note :
    1. Month and Date order can be in any order.
    2. Separator can be anything, that will be ignored.
    3. Only 3 characters are considered in Month part.

    const d=new Date("29 JUN 2024");
    const d=new Date("JUN 29 2024");
    const d=new Date("29*JUN*2024");//any separator
    const d=new Date("29 JUne 2024");//any case
"Invalid Date" will be returned if the provided date is in incorrect format.

Javascript allows Date manipulation with different methods.

Comments

Popular posts from this blog

Java Script Array Methods