-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatetime.js
52 lines (34 loc) · 1004 Bytes
/
datetime.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Initialize as current date object
var d = new Date();
// Initialize as custom date object
var d = new Date(2018, 11, 24, 10, 33, 30, 0); // Arguments- Date(year, month, day, hours, minutes, seconds, milliseconds)
// Initializing date object with date string
var d = new Date("October 13, 2014 11:13:00");
// By default date format:-Sun Nov 01 2020 23:21:21 GMT+0530 (India Standard Time)
// Date to UTC Date
utcDate=d.toUTCString();
// Date to Date String
ds=d.toDateString();
// Date String - ISO Format
isoDate=d.toISOString();
// Parse Date String to milliseconds
var msec = Date.parse("March 21, 2012");
// Get time from date
var d=new Date();
var time=d.getTime();
// Get Full Year
var year=d.getFullYear();
// Get Month
var month=d.getMonth();
// Get Date
var date=d.getDate();
// Get Hours
var hours=d.getHours();
// Get Minutes
var mins=d.getMinutes();
// Get Seconds
var secs=d.getSeconds();
// Get Milliseconds
var msecs=d.getMilliseconds();
// Get Day
var day=d.getDay();