Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,920 --> 00:00:05,180
Now that we are printing out this date let's take a look at another pipe that we can use to very easily
2
00:00:05,180 --> 00:00:06,830
format dates with Angular.
3
00:00:07,160 --> 00:00:08,870
I'm gonna go back to that API list.
4
00:00:08,870 --> 00:00:14,480
I'm going to find the documentation for the data byte we can use this pipe to format some kind of date
5
00:00:14,560 --> 00:00:15,720
automatically.
6
00:00:15,950 --> 00:00:19,970
The syntax is very similar to the title case one that we just used a moment ago.
7
00:00:20,030 --> 00:00:26,280
We're gonna write out some value or some expression in the pipe symbol and just the word date by itself.
8
00:00:26,300 --> 00:00:30,980
Everything else you see list inside of here are some options so we can use to customize the format in
9
00:00:30,980 --> 00:00:32,730
which the date gets printed out.
10
00:00:32,870 --> 00:00:36,110
Right now let's just try to use the date pipe by itself.
11
00:00:36,110 --> 00:00:43,060
I'll go back over to my template a find where we are printing out date and I'll write in the date pipe
12
00:00:43,060 --> 00:00:44,250
like so.
13
00:00:44,260 --> 00:00:51,030
And the reason that I chose that property name of dates inside of our actual component right here is
14
00:00:51,030 --> 00:00:55,830
so I can kind of highlight one very confusing thing that you're going to run into rather quickly when
15
00:00:55,830 --> 00:01:01,550
you start to work with dates though on the left hand side is a reference to a property on our app component.
16
00:01:01,610 --> 00:01:04,660
If I mouse over it we'll see yep that's exactly what it is.
17
00:01:04,790 --> 00:01:08,000
Then on the right hand side is the date height.
18
00:01:08,000 --> 00:01:13,310
These are two very different things but it's really confusing to look at this right now.
19
00:01:13,310 --> 00:01:17,840
Well I would highly recommend that wherever possible rather than using property names or stuff like
20
00:01:17,840 --> 00:01:20,660
that that you're going to write out inside a template of dates.
21
00:01:20,660 --> 00:01:23,360
You ever expect to actually format that with the date pipe.
22
00:01:23,360 --> 00:01:27,890
Maybe try to use a different property name and date is otherwise you end up with a scenario right here
23
00:01:28,180 --> 00:01:31,130
where it starts to get a little bit confusing about what's going on.
24
00:01:31,250 --> 00:01:38,090
Again on the left is the property name on our class on the right is the date pipe that out of the way.
25
00:01:38,120 --> 00:01:39,980
Let's see this and just see what happens.
26
00:01:41,160 --> 00:01:46,620
I'll go back over to my application I'll enter in a month a day and a year you'll notice right away
27
00:01:46,800 --> 00:01:49,230
that we get this nicely formatted date.
28
00:01:49,380 --> 00:01:53,790
If your date looks a little bit different than mine that is totally fine angular reads some settings
29
00:01:53,790 --> 00:01:58,660
inside your browser to figure out how it should format the date again if you see something different.
30
00:01:58,740 --> 00:02:00,140
Only OK.
31
00:02:00,370 --> 00:02:04,810
Let's take a look at some documentation around pipe and get a better idea of how to format this thing
32
00:02:05,500 --> 00:02:11,260
in particular if we look back at our markup remember we want to show the word of DEC or whatever month
33
00:02:11,290 --> 00:02:15,910
we selected and then the day then a comma and then the full year.
34
00:02:15,910 --> 00:02:21,490
Let's take a look at the documentation and understand how to do that on the date pipe documentation
35
00:02:21,490 --> 00:02:30,630
page we can scroll down a little bit with section that is called custom format option a custom format
36
00:02:30,630 --> 00:02:36,550
options tells you exactly how to write out a date with any format you can possibly imagine.
37
00:02:36,600 --> 00:02:41,130
For example let me show you how we would write out just the day by itself.
38
00:02:41,400 --> 00:02:48,610
Like I want to see just the day just the number 15 do so I would look on this table and find a section
39
00:02:48,640 --> 00:02:52,230
telling me how to print out days of the month year era.
40
00:02:52,230 --> 00:02:58,950
There is year there is month week day week in the month and finally day of the month.
41
00:02:59,020 --> 00:03:00,070
That's what we're looking for.
42
00:03:00,860 --> 00:03:03,110
But then going to find out the different options here.
43
00:03:03,130 --> 00:03:06,030
Which one is most appropriate for our use case.
44
00:03:06,220 --> 00:03:10,810
So these two options right here are saying that we can either just print out the day by itself like
45
00:03:10,810 --> 00:03:14,530
the number 1 1 5 4 15 and so on.
46
00:03:14,530 --> 00:03:20,100
Or alternatively we can print out the date in such a way that always two digits are showing.
47
00:03:20,100 --> 00:03:25,120
So in other words if the day is 1 like the first day of the year there will be a 0 added to the left
48
00:03:25,120 --> 00:03:31,450
hand side just to arbitrarily increase the number of digits to do let's try using the very simple way
49
00:03:31,450 --> 00:03:32,410
right here.
50
00:03:32,430 --> 00:03:39,240
But I want to print out just the day by itself and to do so I would write in the code of the lowercase
51
00:03:39,250 --> 00:03:39,780
d.
52
00:03:40,120 --> 00:03:41,950
But where do we write that.
53
00:03:41,980 --> 00:03:44,930
Well we need to figure out how to provide arguments to a pipe.
54
00:03:45,430 --> 00:03:47,940
Let's go back over to our editor and figure that out.
55
00:03:48,910 --> 00:03:55,860
To provide an argument to a pipe you write in a colon right after the pipe well then put in double quotes
56
00:03:55,860 --> 00:04:01,230
to form a string and then inside there it will write in whatever we want to provide you that pipe as
57
00:04:01,230 --> 00:04:07,260
an argument in our case we want to provide an argument of just lowercase d inside that string which
58
00:04:07,260 --> 00:04:13,230
is going to tell the pipe to print out our date a little bit differently open in lowercase d like so
59
00:04:15,200 --> 00:04:24,790
then save this I will flip back over now if I enter in 12 15 1950 you'll see that I only get the date
60
00:04:24,820 --> 00:04:31,180
by itself we can reference this table and use these little character codes right here.
61
00:04:31,180 --> 00:04:37,780
These little kind of like w w w E's all these different codes right here to exactly customize how the
62
00:04:37,780 --> 00:04:39,410
date gets printed out.
63
00:04:39,460 --> 00:04:42,700
We can also repeat these things as many times as we want.
64
00:04:42,700 --> 00:04:49,300
For example I couldn't put in like so I can even put in like dashes in there flashes whatever you can
65
00:04:49,300 --> 00:04:50,110
possibly imagine.
66
00:04:51,040 --> 00:04:56,300
If I try to run that now I'm going to see a very funny looking date but it will print out regardless.
67
00:04:56,590 --> 00:05:03,210
I'll see 15 printed over and over and over again I get those dashes and slashes that's pretty much it
68
00:05:03,210 --> 00:05:04,260
for the date pipe.
69
00:05:04,290 --> 00:05:09,290
All you really need to know is that well the date pipe exists if you ever want to custom format it.
70
00:05:09,330 --> 00:05:10,370
Take a look at this.
71
00:05:10,470 --> 00:05:17,320
A steam table right here this you know something else so you might make yourself right above that section
72
00:05:17,540 --> 00:05:22,410
or a couple of reformatted ways to print out your date as well.
73
00:05:22,450 --> 00:05:28,150
For example if we provide a argument of short dates that would be equivalent to or getting something
74
00:05:28,150 --> 00:05:32,610
like a month and the day and then a two digit year at the end.
75
00:05:32,740 --> 00:05:37,070
Then some scenarios this might actually match up with what you are trying to do as a matter of fact.
76
00:05:37,130 --> 00:05:42,070
Here's long date right here that actually matches the date format that you and I are trying to show
77
00:05:42,100 --> 00:05:47,980
which is the long month of a day and then the year with a comma in between the date and the year but
78
00:05:48,010 --> 00:05:50,830
just for some practice rather than using this shortcut.
79
00:05:50,860 --> 00:05:55,140
Let's use the custom format options and figure out how we would do this ourselves.
80
00:05:55,310 --> 00:06:00,870
We would first need to look up the character code to print out the old month we'll look that up really
81
00:06:00,870 --> 00:06:01,710
quickly.
82
00:06:01,740 --> 00:06:03,500
Here's a month section right here.
83
00:06:03,510 --> 00:06:05,050
Print out a full month name.
84
00:06:05,070 --> 00:06:07,820
We write out for capital ends in a row.
85
00:06:08,030 --> 00:06:13,660
I would go back over inside the string but in or capital ends.
86
00:06:14,080 --> 00:06:18,490
Next up we want to show a single day or day the month.
87
00:06:18,830 --> 00:06:19,980
We just looked at that section.
88
00:06:19,990 --> 00:06:21,010
It's a little bit lower.
89
00:06:21,020 --> 00:06:29,090
We'll fine day the month lowercase d but in lowercase Do you like so next is a comma.
90
00:06:29,090 --> 00:06:30,190
Well that's pretty straightforward.
91
00:06:30,200 --> 00:06:32,090
All we have to do is a comma.
92
00:06:32,090 --> 00:06:35,290
And then finally a four digit year a very four digit year.
93
00:06:35,300 --> 00:06:38,420
I'll scroll back up find the year section.
94
00:06:38,470 --> 00:06:41,930
Here it is right here but a printout a year by itself.
95
00:06:42,030 --> 00:06:45,390
You just have to do lowercase Y.
96
00:06:45,430 --> 00:06:51,900
I'll go back over and then do lowercase y and that should be at I'm going to say this one last test
97
00:06:51,900 --> 00:06:52,520
here.
98
00:06:52,770 --> 00:06:56,400
I'll put in December 15th 1950.
99
00:06:56,400 --> 00:06:57,030
There we go.
100
00:06:57,030 --> 00:06:57,790
Looks very good.
101
00:06:58,800 --> 00:06:59,070
OK.
102
00:06:59,100 --> 00:07:00,780
So again that is the date pipe.
103
00:07:00,780 --> 00:07:02,940
Again you really just need to know that it exists.
104
00:07:02,940 --> 00:07:07,010
You can use either these custom form matters or the shortcuts either one.
105
00:07:07,020 --> 00:07:07,800
Totally fine.
106
00:07:08,530 --> 00:07:09,870
Now we've got this pipe put together.
107
00:07:09,870 --> 00:07:14,550
Let's take a pause right here and then move on to our last built in pipe in the next video.
11176
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.