Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Date

JS Date

JavaScript Date let us work with dates.

Date Objects

JavaScript Date objects are static which means, it will not change as time changes.

By default, JavaScript will use the browser's time zone and display a date as a full text string

Fri Jun 30 2023 12:12:30 GMT+0530 (India Standard Time)

					 
        
          const d = new Date();
          const d = new Date("2022-03-25");
        
      
Creating Date Objects

Date objects are created with the new Date() constructor.

					 
        
          new Date();
          new Date(date string);

          new Date(year,month);
          new Date(year,month,day);
          new Date(year,month,day,hours);
          new Date(year,month,day,hours,minutes);
          new Date(year,month,day,hours,minutes,seconds);
          new Date(year,month,day,hours,minutes,seconds,ms);

          new Date(milliseconds);
        
      
JavaScript new Date()

new Date() creates a date object with the current date and time, or supplied date format. new Date() can take any format of string dates, years, months, day, hours, minutes, seconds, milliseconds.

JavaScript counts months from 0 (January) to 11 (December).

Specifying a day or month higher than max, will not result in an error but add the overflow to the next month or year.

One and two digit years will be interpreted as 19xx.

If we only supply year (single value), it will treated as milliseconds.

					 
        
          conts currentDateTime = new Date();

          conts dateTime1 = new Date("June 30, 2023 11:59:00");
          conts dateTime2 = Date("2023-06-30");

          const dateTime3 = new Date(2018, 11, 24, 10, 33, 30, 0);

          const dateTime4 = new Date(2018, 15, 24, 10, 33, 30);
          const dateTime5 = new Date(2019, 3, 24, 10, 33, 30);

          const dateTime6 = new Date(2018, 5, 35, 10, 33, 30);
          const dateTime7 = new Date(2018, 6, 5, 10, 33, 30);

          const dateTime8 = new Date(2018, 11, 24, 10, 33, 30);
          const dateTime9 = new Date(2018, 11, 24, 10, 33);
          const dateTime10 = new Date(2018, 11, 24, 10);
          const dateTime11 = new Date(2018, 11, 24);
          const dateTime12 = new Date(2018, 11);
          const dateTime13 = new Date(2018); // This will treated as milliseconds not year

          const dateTime14 = new Date(99, 11, 24);
          const dateTime15 = new Date(9, 11, 24);
        
      
JavaScript Stores Dates as Milliseconds

JavaScript stores dates as number of milliseconds since January 01, 1970.

Zero time is January 01, 1970 00:00:00 UTC.

One day (24 hours) is 86 400 000 milliseconds.

					 
        
          const dateTime1 = new Date(100000000000); // "Sat Mar 03 1973 15:16:40 GMT+0530 (India Standard Time)"
          const dateTime2 = new Date(-100000000000); // "Mon Oct 31 1966 19:43:20 GMT+0530 (India Standard Time)"

          // One Day (24 * 60 * 60 * 1000) is 86400000 milliseconds
          const dateTime3 = new Date(24 * 60 * 60 * 1000);
          const dateTime4 = new Date(86400000);
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved