-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.js
92 lines (68 loc) · 2.25 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
let d= new Date();
console.log(d);
let d1= new Date(2000,6,13,10);
console.log(d1.toISOString());
const d2=new Date("October 13 , 2012 11:13:00");
console.log(d2.toDateString());
let d3=new Date();
console.log(d3.toUTCString());
//-----------------=-----------------------=Date formate--------------=
//ISO dates can be written with added hours, minutes, and seconds (YYYY-MM-DDTHH:MM:SSZ):
let df=new Date("2019-6-20");
console.log(df.toUTCString());
let df1=new Date("2000");
console.log(df1.toDateString());
//----------Short Dates-----------------
let df2=new Date("7/13/2000");
console.log(df2.toDateString());
//----------Long Dates-----------------
let dl=new Date("January ,25,2018");
console.log(dl.toDateString());
//-----------------parse date-------------
let dp=Date.parse("January ,25,2018");
const dp1=new Date(dp);
console.log(dp);
console.log(dp1);
//------------------Get date from youser------------
const dg=new Date();
dg.getTime();
console.log(dg.toISOString());
//------------------get full year method-------------
const dy=new Date();
dy.getFullYear();
console.log(dy);
//----------------get full month---------------------
const dm=new Date();
console.log(dm.getMonth());
//--------------Get Day-----------------------------
const dd= new Date();
console.log(dd.getDate());
//---------------get houre--------------------------
const gh=new Date();
console.log(gh.getHours());
//-----------you can use the the array to get the day name of that day 0----------------
const days=["Sunday","Monday","Tusday","WEdnesday","Thurday","Friday","Sturday"];
const gd=new Date();
console.log(days[gd.getDay()]);
//---------------------Sete full year------------------
const ds=new Date();
console.log(ds.setFullYear(2000,6,13));
//------------------Set ful month--------------------
const sm=new Date();
console.log(sm.setMonth(11));
//-----------------set full hour------------------------
const fm=new Date();
console.log(fm.setHours(24));
//------------Comparsion----------------------------------
let text;
const today=new Date();
const somday=new Date();
somday.setFullYear(2100,10,2);
if (somday>today) {
text="Today is before January 14, 2100.";
console.log(text);
}
else{
text = "Today is after January 14, 2100.";
console.log(text);
}