Theme Layout

Boxed or Wide or Framed

Wide

Theme Translation

Display Featured Slider

Featured Slider Styles

Display Grid Slider

yes

Grid Slider Styles

Display Trending Posts

Display Author Bio

Display Instagram Footer

off

Dark or Light Style

Light

Blog Archive

Powered by Blogger.

Wednesday, February 15, 2017

[JavaScript] Dates


# JavaScript Dates


● JavaScript Date Formats

 A JavaScript Date can be written as a string:
  Wed Fed 15 2017 18:59:40 GMT+0900 (KST)
or as a number:  1487152780771 
Dates written as numbers, specifies the number of milliseconds since Jan 1,1970,00:00:00

● Displaying Dates

 In this tutorial we use a script to display dates inside a <p> element with id="prac".

● Creating Date Objects

 The Date object lets us work with dates. A date consists of a year, a month, a day, an hour, a minute, a second, and milliseconds. 
Date objects are created with the new Date() constructor.
There are 4 ways of initiating a date.


Using new Date(), creates a new date object with the current date and time.


When using new Date(date string), creates a new date object from the specified date and time.


Using new Date(number), creates a new date objects as zero  time plus the number.
Zero time is 01 Jan 1970 00:00:00 UTC. The number is specified in milliseconds.


Using new Date(7 numbers), creates a new date object with the specified date & time.
The 7 numbers specify the year, month, day, hour, minute, second, millisecond.


new Date(7 number) can be used only typed 4 numbers. minute, second and millisecond can be omitted.
JSP counts months from 0 to 11, January is 0, December is 11.

● Displaying Dates

 When I display a date object in HTML, it is automatically converted to a string, with the toString() method.


The toUTCString() method converts a date to a UTC string ( a date display standard).

 
The toDateString() method converts a date to a more readable format.


Date objects are static. The computer time is ticking, but date objects, once created, are not.

● Time Zones

 When setting a date, without specifying the time zone, JSP will use the browser's time zone.
 When getting a date, without specifying the time zone, the result is converted to the browser's time zone.
 In other words, If a date/time is created in GMT ( Greenwich Mean Time ), the date/time will be converted to CDT ( Central US Daylight Time ) if a user browses from central US.

QuickEdit
Unknown
0 Comments
Share This Post :

You Might Also Like

No comments:

Post a Comment

Follow @SunriseSunsetBlog