1
00:00:00,660 --> 00:00:07,570
All right guys so dates and times are very important in programming and Javascript has what's called

2
00:00:07,570 --> 00:00:10,820
the Date object that we can use to do certain things with date.

3
00:00:10,820 --> 00:00:20,010
So let's go ahead and let's create a variable here let's just create our Val variable like we've been

4
00:00:20,010 --> 00:00:20,620
doing.

5
00:00:20,940 --> 00:00:24,560
And I'm going to set Val next.

6
00:00:25,140 --> 00:00:34,260
You know what I'm going to do is I'm going to set a constant called today and we're going to set it

7
00:00:34,260 --> 00:00:36,010
to a new date.

8
00:00:36,030 --> 00:00:40,360
OK so this is this is basically instantiating the Date object.

9
00:00:40,380 --> 00:00:44,850
And if we don't pass anything in here by default it's going to be today's date.

10
00:00:44,850 --> 00:00:55,920
So if we go down and we say that all equals today and then we cancel the log thou and save.

11
00:00:55,920 --> 00:00:58,800
You'll see down here we get today's date.

12
00:00:58,970 --> 00:00:59,310
All right.

13
00:00:59,310 --> 00:01:01,220
And if we were to look at the type.

14
00:01:01,520 --> 00:01:09,240
So if we see a type of this type of well we're going to get objects because a date is actually a reference

15
00:01:09,240 --> 00:01:13,900
type which is an object we could change it to a string if we want.

16
00:01:13,920 --> 00:01:25,070
So if we said Konst not actually we couldn't do it like that we'd have to do Val equals today Daut to

17
00:01:25,080 --> 00:01:27,420
string and then it would be a string.

18
00:01:27,420 --> 00:01:33,800
All right so we could do that if we wanted to if you wanted to do some stuff with strings with the date.

19
00:01:33,870 --> 00:01:40,140
Anyways I'm going to go back to just logging the bell and what I want to do now is show you how we can

20
00:01:40,140 --> 00:01:42,130
change it to a different date.

21
00:01:42,540 --> 00:01:53,610
So I'll create another variable here called birth day and I'll said it's a new date and then and here

22
00:01:53,940 --> 00:01:56,770
we can specify this in many different ways.

23
00:01:56,760 --> 00:02:05,400
So one way would be to do the nine dash 10 dash 1981 and then if we were to change the vowel which is

24
00:02:05,400 --> 00:02:13,440
what we're logging to birthday and save you'll see it's in the same format except it's now September

25
00:02:13,440 --> 00:02:15,450
10th 1981.

26
00:02:15,450 --> 00:02:17,080
Now this here is the time.

27
00:02:17,250 --> 00:02:25,920
So we have the hours the minutes the seconds if we want to add that we could go ahead and put in let's

28
00:02:25,920 --> 00:02:28,870
say 11.

29
00:02:28,880 --> 00:02:31,990
11:25 0 0.

30
00:02:32,220 --> 00:02:33,020
And save.

31
00:02:33,030 --> 00:02:35,870
And now you can see that the time has changed.

32
00:02:35,880 --> 00:02:37,460
All right.

33
00:02:38,130 --> 00:02:40,160
Now there's many ways to do this.

34
00:02:40,170 --> 00:02:46,180
I'm actually going to turn this into a let so that I can override this so that I can redeclare it.

35
00:02:46,240 --> 00:02:52,620
So I'm going to say let actual Just call I'll just copy this just to show you that there's other ways

36
00:02:52,620 --> 00:02:56,100
that we can create data so I can actually say

37
00:02:59,040 --> 00:03:08,260
September 10 1981 and save the birthday has already been declared.

38
00:03:08,280 --> 00:03:10,860
Oh you don't want to put that again.

39
00:03:11,220 --> 00:03:14,720
And you can see that it also gives us September 10.

40
00:03:14,960 --> 00:03:16,260
All right.

41
00:03:16,260 --> 00:03:19,290
We could also do it.

42
00:03:19,610 --> 00:03:20,360
Get rid of that law.

43
00:03:20,360 --> 00:03:21,660
We can also do it this way.

44
00:03:21,660 --> 00:03:29,060
It's a nine slash 10 slash 1981 and there's a lot of ways to do it so you may want to look at the documentation

45
00:03:30,800 --> 00:03:31,970
on what is it's

46
00:03:34,540 --> 00:03:45,040
javascript date object say so you know on the Mozilla on MDI and this will show you a lot of different

47
00:03:45,040 --> 00:03:48,350
things here and we're going to go over most of this.

48
00:03:48,400 --> 00:03:53,860
We're going to go over like you know the get date get DAY GET year all this stuff.

49
00:03:54,130 --> 00:03:58,750
But this gives you all the information about the date object.

50
00:03:58,750 --> 00:03:59,080
All right.

51
00:03:59,080 --> 00:04:03,360
So let's say we want to get the month.

52
00:04:03,370 --> 00:04:09,600
All right so I'm going to use today instead of birthday so say Val equals today Daut.

53
00:04:09,730 --> 00:04:12,030
Get month.

54
00:04:12,280 --> 00:04:17,710
Now if I say this you'll see it's going to log 10 and if you look at the date it's 11:09 it's actually

55
00:04:17,710 --> 00:04:18,850
November.

56
00:04:18,850 --> 00:04:21,490
But this is actually zero based.

57
00:04:21,610 --> 00:04:24,690
So zero would be January.

58
00:04:24,700 --> 00:04:33,880
And just to show you just real quick if I were to put in here 1 1 20:17 and save it'll give us zero

59
00:04:34,150 --> 00:04:35,380
as the month.

60
00:04:35,410 --> 00:04:36,650
OK.

61
00:04:36,700 --> 00:04:40,260
So just keep that in mind and that confuses a lot of people.

62
00:04:40,420 --> 00:04:52,160
If we want to get the date for the day of the month we could do that equals today Daut get date.

63
00:04:52,210 --> 00:04:57,460
So if we go ahead and save that we get nine and you can see that it is in fact 11:9.

64
00:04:57,460 --> 00:05:08,830
If we want to get the day we could say today Daut good day and save and we get four so we get a numerical

65
00:05:09,580 --> 00:05:12,850
representation of the day today is actually Wednesday.

66
00:05:12,850 --> 00:05:18,610
So it's basically going Sunday Monday Tuesday Wednesday which is the fourth day.

67
00:05:18,640 --> 00:05:18,970
All right.

68
00:05:18,970 --> 00:05:22,000
So we'll see if we can also get the.

69
00:05:22,000 --> 00:05:23,140
Year.

70
00:05:23,740 --> 00:05:28,140
So it's a well equals today.

71
00:05:28,160 --> 00:05:31,750
Dogs get a full year.

72
00:05:31,900 --> 00:05:33,490
That gives us 20:17

73
00:05:36,220 --> 00:05:40,790
we can also get the we can get we can deal with times.

74
00:05:40,790 --> 00:05:48,240
So if we want to get the hours we can say get ours which gives us 11.

75
00:05:48,480 --> 00:05:52,290
And if you look down here it's 11:20.

76
00:05:52,380 --> 00:05:53,690
We can get the minutes

77
00:05:57,800 --> 00:06:00,170
you look at that we get 21.

78
00:06:00,230 --> 00:06:01,400
It's 11:21.

79
00:06:01,400 --> 00:06:02,610
We can get seconds

80
00:06:09,900 --> 00:06:16,170
like that we get 14 and if I reload you see that that's going to change every second we can even get

81
00:06:16,170 --> 00:06:23,010
milliseconds if I want to do get milliseconds.

82
00:06:23,510 --> 00:06:32,500
Well actually it should be a lowercase s or flat wrong too or else.

83
00:06:32,580 --> 00:06:42,530
So that gives us mere seconds ago all right and then we can also get a time stamp the current time stamp

84
00:06:42,540 --> 00:06:49,530
so if we say Val equals today Daut get the time and save.

85
00:06:49,530 --> 00:06:51,080
That gives us the time stamp.

86
00:06:51,150 --> 00:06:51,440
OK.

87
00:06:51,450 --> 00:06:56,360
And that's going to change with every reload time stamp.

88
00:06:56,360 --> 00:07:02,120
It's basically the amount of time the amount of seconds that have passed since what is it January 1st

89
00:07:02,180 --> 00:07:03,740
1970.

90
00:07:04,280 --> 00:07:09,710
So another thing we can do is we can actually set all this stuff as well.

91
00:07:09,710 --> 00:07:18,740
So for instance let's take the birthday date we have up there and let's say Daut set month and we'll

92
00:07:18,740 --> 00:07:21,310
set it to high.

93
00:07:21,320 --> 00:07:23,170
And then I just want to log birthday

94
00:07:26,150 --> 00:07:29,170
and now we get March 10th.

95
00:07:29,280 --> 00:07:32,930
OK it started this September 10th but now it's March 10th.

96
00:07:33,290 --> 00:07:37,480
So we want to change.

97
00:07:38,210 --> 00:07:46,760
Let's do set a date and we'll set that to 12 so we'll save that.

98
00:07:46,760 --> 00:07:49,190
Now we get March 12.

99
00:07:49,190 --> 00:07:49,610
All right.

100
00:07:49,610 --> 00:08:02,680
We can also do a set full year and we'll set that to 19 let's say 1985 save.

101
00:08:02,690 --> 00:08:05,510
And now it's March 12th 1985.

102
00:08:05,510 --> 00:08:07,100
We can also set the time.

103
00:08:07,130 --> 00:08:09,280
So birthday does set

104
00:08:11,410 --> 00:08:13,640
hours.

105
00:08:13,840 --> 00:08:20,060
So that to say three save that now it's three o'clock

106
00:08:22,690 --> 00:08:26,730
two minutes.

107
00:08:27,080 --> 00:08:29,160
So so the minutes to 30.

108
00:08:29,160 --> 00:08:33,200
So now 3:30 and we can even set the seconds

109
00:08:37,400 --> 00:08:41,470
so that to I say 25.

110
00:08:41,480 --> 00:08:41,720
All right.

111
00:08:41,720 --> 00:08:47,330
So three thirty 25 so we can manipulate dates as well.

112
00:08:47,330 --> 00:08:47,830
All right guys.

113
00:08:47,830 --> 00:08:52,010
That's going to do it for dates if you want to learn a little more of both the date object.

114
00:08:52,010 --> 00:08:59,480
I'd suggest looking at the D.N. documentation but that's going to be it for now and the next video we're

115
00:08:59,480 --> 00:09:01,550
going to start to look at control structures.

116
00:09:01,550 --> 00:09:07,790
We're going to look at conditionals so if statements comparison operators and then we'll move on to

117
00:09:07,790 --> 00:09:10,850
switches and functions and all that good stuff.

118
00:09:10,850 --> 00:09:12,110
All right so that's it.

119
00:09:12,110 --> 00:09:13,700
I will see you in the next lecture.

