1
00:00:02,250 --> 00:00:09,120
Now to come to an end in this module, there's one last built-in or global constructor function you could

2
00:00:09,120 --> 00:00:15,940
say that helps you deal with dates and that's the date object and constructor function.

3
00:00:16,110 --> 00:00:22,190
You can use date in a broad variety of ways and attached you find documentation that allows you to

4
00:00:22,190 --> 00:00:24,000
have deeper into date.

5
00:00:24,000 --> 00:00:28,270
You can for example create a new date object like this

6
00:00:28,350 --> 00:00:29,750
and what this gives you

7
00:00:29,790 --> 00:00:34,410
if I hit enter is indeed the current date and timestamp here,

8
00:00:34,500 --> 00:00:39,290
so that's the current date and time at which I'm recording this specific video here,

9
00:00:39,300 --> 00:00:41,210
this is what you get with new date.

10
00:00:41,310 --> 00:00:48,300
Now actually, this is really an object you can work with though. If we store it in a constant, then on

11
00:00:48,300 --> 00:00:52,660
this constant, so on this stored object, we get a couple of methods,

12
00:00:52,680 --> 00:00:58,450
for example we can call get date to get the day in month, 24th

13
00:00:58,470 --> 00:01:06,600
in this case, we got get day to get the day in this week and so on. So there are lots of methods that

14
00:01:06,600 --> 00:01:13,590
allow you to analyze this date, get the time for example since the beginning of time in Javascript land

15
00:01:13,620 --> 00:01:16,520
which is January 1st 1970,

16
00:01:16,530 --> 00:01:23,790
so since then, this is the time of milliseconds that has passed and this can sometimes be helpful for

17
00:01:23,850 --> 00:01:26,740
calculating differences and so on and much more,

18
00:01:26,830 --> 00:01:29,870
so there are a bunch of methods you can call to work with a date.

19
00:01:30,060 --> 00:01:37,250
You can also construct a date with new date by passing an argument to the date constructor,

20
00:01:37,250 --> 00:01:43,040
if you don't pass anything, you get the current timestamp but you can also pass in a date instead which

21
00:01:43,040 --> 00:01:45,910
Javascript then tries to parse.

22
00:01:45,960 --> 00:01:49,010
Now for one, you can pass in an existing date object,

23
00:01:49,010 --> 00:01:55,640
this would simply store that date as a new object in date2 but you can also pass in the string to describe

24
00:01:55,640 --> 00:01:56,080
a date

25
00:01:56,120 --> 00:02:00,300
and of course then Javascript will do its best to pass this as a date,

26
00:02:00,320 --> 00:02:06,590
for example I could pass in 07/11/19 and now what

27
00:02:06,590 --> 00:02:12,440
Javascript derived is July 11th 2019 from this date.

28
00:02:12,440 --> 00:02:18,020
Now again, the attached resources allow you to dig deeper and find out which formats you can use there,

29
00:02:18,110 --> 00:02:22,360
how you can also specify minutes and hours and so on and much more.

30
00:02:22,490 --> 00:02:28,190
Now these date objects can be really useful because for example if you would want to calculate the difference

31
00:02:28,190 --> 00:02:35,680
between this first date, which is today and date2 which is in July, then we can just execute date minus

32
00:02:35,690 --> 00:02:39,720
date2 and this gives us the difference in milliseconds

33
00:02:39,860 --> 00:02:46,280
and therefore if we take that difference and for example divide it by 1000 to have the difference in seconds, divide it

34
00:02:46,280 --> 00:02:53,150
by 60 to have a difference in minutes, divide it by 60 again to have the difference in hours and then by

35
00:02:53,150 --> 00:02:57,710
24, we get the difference in days since that date,

36
00:02:57,770 --> 00:03:00,640
so that's just one example of what you can do there.

37
00:03:01,340 --> 00:03:03,710
So definitely check out that date object

38
00:03:03,710 --> 00:03:08,810
also with help of the attached documentation if you need to work with dates in your application, if

39
00:03:08,810 --> 00:03:13,220
you need to store a date, run some date calculation or anything like that,

40
00:03:13,250 --> 00:03:14,990
this object has got you covered.
