-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.js
27 lines (16 loc) · 1.18 KB
/
date.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
let date = new Date()
console.log(date)
// Date object stores date,time and provides methods for date/time management
// An integer number representing the number of milliseconds that has passed since the beginning of 1970 is called a timestamp.
// We can always create a date from a timestamp using new Date(timestamp) and convert the existing Date object to a timestamp using the date.getTime() method (see below).
let start = Date.now(); // milliseconds count from 1 Jan 1970
// Date parse
// The method Date.parse(str) can read a date from a string.
// The string format should be: YYYY-MM-DDTHH:mm:ss.sssZ, where:
// YYYY-MM-DD – is the date: year-month-day.
// The character "T" is used as the delimiter.
// HH:mm:ss.sss – is the time: hours, minutes, seconds and milliseconds.
// The optional 'Z' part denotes the time zone in the format +-hh:mm. A single letter Z would mean UTC+0.
// Shorter variants are also possible, like YYYY-MM-DD or YYYY-MM or even YYYY.
// The call to Date.parse(str) parses the string in the given format and returns the timestamp (number of milliseconds from 1 Jan 1970 UTC+0). If the format is invalid, returns NaN.
// Source https://javascript.info/date