You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
document.write("The Date Object in JavaScript!"+"<br /><br />");
2
+
3
+
/*
4
+
The Date Object
5
+
6
+
*/
7
+
8
+
letmyDate=newDate();// Getting Current Date.
9
+
console.log("Current Date : "+myDate);
10
+
11
+
// Getting Past Date
12
+
letmyPastDate=newDate(1545,11,2);// Month is 0 to 11. 0 means january and 11 means decemeber wise.
13
+
console.log("Past Date : "+myPastDate);
14
+
15
+
// Getting Future Date
16
+
letmyFutureDate=newDate(2515,0,31);// Month is 0 to 11. 0 means january and 11 means decemeber wise.
17
+
console.log("Future Date : "+myFutureDate);
18
+
19
+
20
+
21
+
// Calling methods from date object
22
+
letbirthday=newDate(1985,0,15,11,15,25);// (YYYY, MM, DD, HH, mm, ss)
23
+
console.log("Birthday : "+birthday);
24
+
25
+
console.log("Birthday Month : "+birthday.getMonth());// get the month of the date (0 - 11)
26
+
console.log("Birthday Year : "+birthday.getFullYear());// get the full year (YYYY)
27
+
console.log("Birthday Date : "+birthday.getDate());// get the date of the month (0 - 31)
28
+
console.log("Birthday Day : "+birthday.getDay());// get the day of week (0 -6)
29
+
console.log("Birthday Hour : "+birthday.getHours());// get the hour of the date (0 - 23)
30
+
console.log("Birthday Time : "+birthday.getTime());// get the number of miliseconds since 1st jan 1970
31
+
32
+
// Why we need getTime() method?
33
+
// lets make another date as birthday2, but values same.
34
+
letbirthday2=newDate(1985,0,15,11,15,25);
35
+
36
+
// Lets create if else statement to check this birthday and birthday2 objects are same or not
37
+
if(birthday===birthday2){
38
+
39
+
console.log("Birthdays are equal");
40
+
41
+
}else{
42
+
43
+
console.log("Birthdays are not equal");
44
+
45
+
}
46
+
// This if-else gives "Birthdays are not equal" statement. but these two birthdays have same values then why?
47
+
// That because birthday and birthday2 are objects of Date() object are not same thats why throwing not equal satement. Then how we check these values of birthdays.
0 commit comments