{"id":11016,"date":"2024-07-29T06:39:32","date_gmt":"2024-07-29T06:39:32","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=11016"},"modified":"2024-07-29T06:57:09","modified_gmt":"2024-07-29T06:57:09","slug":"write-angular-date-pipe-in-angular-2","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/angular\/write-angular-date-pipe-in-angular-2","title":{"rendered":"Angular 2: How to Write a Angular Date Pipe"},"content":{"rendered":"<p>The Angular DatePipe is a built-in pipe module that allows you to format dates in your Angular templates. It provides a convenient way to transform dates into different formats according to locale rules<\/p>\n<h2>Syntax<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">{{ value_expression | date[:format] [:timezone] [:locale] }}\r\n<\/pre>\n<p>We have to import the <strong>\u201cCommon Module\u201d<\/strong> library in angular modules. If we use the angular 16+ version and we use standalone components then we also have to import this <strong>\u201cCommon Module\u201d<\/strong> to utilize this inbuilt <strong>Date Pipe<\/strong>.<br \/>\nIn syntax we have to pass pipe and date to use <strong>datepipe<\/strong>. We can also pass 3 arguments in the date pipe.<\/p>\n<h3>Arguments:<\/h3>\n<ul>\n<li>1st argument is <strong>format<\/strong> which is predefined else custom format we can use. 2nd argument.<\/li>\n<li>The 2nd argument is <strong>timezone<\/strong>. (e.g., &#8216;+0430&#8217; or &#8216;GMT+0430&#8217;)<\/li>\n<li>The 3rd argument is <strong>locale<\/strong>. Used for date language translation like french for fr<\/li>\n<\/ul>\n<h2>Parameter<\/h2>\n<p><b>value_expression &#8211;<\/b><br \/>\nThis is the date object or a number (milliseconds since UTC epoch) that you want to format.<\/p>\n<p><strong>format &#8211;<\/strong><br \/>\nIt\u2019s optional &amp; you can specify the date-time format. If not provided, it uses the medium-date format <strong>(&#8216;MMM d, y, h:mm:ss a&#8217;).<\/strong><\/p>\n<p><strong>timezone &#8211;<\/strong><br \/>\nSpecifies the time zone &amp; its optional. It can be a string representing a time zone offset (e.g., &#8216;+0430&#8217; or &#8216;GMT+0430&#8217;) or a time zone name from the IANA time zone database (e.g., &#8216;Asia\/Kolkata&#8217;).<\/p>\n<p><strong>locale &#8211;<\/strong><br \/>\nIt is optional parameter in date pipe &amp; specifies the locale code for the formatting rules. Defaults to the current locale of the application. E.g. (\u2018en-US\u2019)<\/p>\n<h2>Pre-defined Formats<\/h2>\n<table>\n<tbody>\n<tr>\n<td><b>Option<\/b><\/td>\n<td><b>Format<\/b><\/td>\n<td><b>Output<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">short<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\/d\/yy, h:mm a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">6\/15\/15, 9:03 AM<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">medium<\/span><\/td>\n<td><span style=\"font-weight: 400;\">MMM d, y, h:mm:ss a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jun 15, 2015, 9:03:01 AM<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">long<\/span><\/td>\n<td><span style=\"font-weight: 400;\">MMMM d, y, h:mm:ss a z<\/span><\/td>\n<td><span style=\"font-weight: 400;\">June 15, 2015 at 9:03:01 AM GMT+1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">full<\/span><\/td>\n<td><span style=\"font-weight: 400;\">EEEE, MMMM d, y, h:mm:ss a zzzz<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Monday, June 15, 2015 at 9:03:01 AM GMT+01:00<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">shortDate<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\/d\/yy<\/span><\/td>\n<td><span style=\"font-weight: 400;\">6\/15\/15<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">mediumDate<\/span><\/td>\n<td><span style=\"font-weight: 400;\">MMM d, y<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Jun 15, 2015<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">longDate<\/span><\/td>\n<td><span style=\"font-weight: 400;\">MMMM d, y<\/span><\/td>\n<td><span style=\"font-weight: 400;\">June 15, 2015<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">fullDate<\/span><\/td>\n<td><span style=\"font-weight: 400;\">EEEE, MMMM d, y<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Monday, June 15, 2015<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">shortTime<\/span><\/td>\n<td><span style=\"font-weight: 400;\">h:mm a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">9:03 AM<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">mediumTime<\/span><\/td>\n<td><span style=\"font-weight: 400;\">h:mm:ss a<\/span><\/td>\n<td><span style=\"font-weight: 400;\">9:03:01 AM<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">longTime<\/span><\/td>\n<td><span style=\"font-weight: 400;\">h:mm:ss a z<\/span><\/td>\n<td><span style=\"font-weight: 400;\">9:03:01 AM GMT+1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">fullTime<\/span><\/td>\n<td><span style=\"font-weight: 400;\">h:mm:ss a zzzz<\/span><\/td>\n<td><span style=\"font-weight: 400;\">9:03:01 AM GMT+01:00<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Custom Formats<\/h2>\n<table>\n<tbody>\n<tr>\n<td><b>Field type<\/b><\/td>\n<td><b>Format<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<td><b>Example Value<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Era<\/span><\/td>\n<td><span style=\"font-weight: 400;\">G, GG &amp; GGG<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Abbreviated<\/span><\/td>\n<td><span style=\"font-weight: 400;\">AD<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">GGGG<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wide<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Anno Domini<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">GGGGG<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Narrow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">A<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Year<\/span><\/td>\n<td><span style=\"font-weight: 400;\">y<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: minimum digits<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2, 20, 201, 2017, 20173<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">yy<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">02, 20, 01, 17, 73<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">yyy<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 3 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">002, 020, 201, 2017, 20173<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">yyyy<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 4 digits or more + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">0002, 0020, 0201, 2017, 20173<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ISO Week-numbering year<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Y<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: minimum digits<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2, 20, 201, 2017, 20173<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">YY<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">02, 20, 01, 17, 73<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">YYY<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 3 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">002, 020, 201, 2017, 20173<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">YYYY<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 4 digits or more + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">0002, 0020, 0201, 2017, 20173<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Month<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 1 digit<\/span><\/td>\n<td><span style=\"font-weight: 400;\">9, 12<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">MM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">09, 12<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">MMM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Abbreviated<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Sep<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">MMMM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wide<\/span><\/td>\n<td><span style=\"font-weight: 400;\">September<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">MMMMM<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Narrow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Month standalone<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 1 digit<\/span><\/td>\n<td><span style=\"font-weight: 400;\">9, 12<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">LL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">09, 12<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">LLL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Abbreviated<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Sep<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">LLLL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wide<\/span><\/td>\n<td><span style=\"font-weight: 400;\">September<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">LLLLL<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Narrow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">ISO Week of year<\/span><\/td>\n<td><span style=\"font-weight: 400;\">w<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: minimum digits<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1&#8230; 53<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">ww<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">01&#8230; 53<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Week of month<\/span><\/td>\n<td><span style=\"font-weight: 400;\">W<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 1 digit<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1&#8230; 5<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Day of month<\/span><\/td>\n<td><span style=\"font-weight: 400;\">d<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: minimum digits<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">dd<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">01<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Week day<\/span><\/td>\n<td><span style=\"font-weight: 400;\">E, EE &amp; EEE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Abbreviated<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tue<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">EEEE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wide<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tuesday<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">EEEEE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Narrow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">EEEEEE<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Short<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tu<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Week day standalone<\/span><\/td>\n<td><span style=\"font-weight: 400;\">c, cc<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 1 digit<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">ccc<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Abbreviated<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tue<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">cccc<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wide<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tuesday<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">ccccc<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Narrow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">cccccc<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Short<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tu<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Period<\/span><\/td>\n<td><span style=\"font-weight: 400;\">a, aa &amp; aaa<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Abbreviated<\/span><\/td>\n<td><span style=\"font-weight: 400;\">am\/pm or AM\/PM<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">aaaa<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wide (fallback to a when missing)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">ante meridiem\/post meridiem<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">aaaaa<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Narrow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">a\/p<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Period*<\/span><\/td>\n<td><span style=\"font-weight: 400;\">B, BB &amp; BBB<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Abbreviated<\/span><\/td>\n<td><span style=\"font-weight: 400;\">mid.<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">BBBB<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wide<\/span><\/td>\n<td><span style=\"font-weight: 400;\">am, pm, midnight, noon, morning, afternoon, evening, night<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">BBBBB<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Narrow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">md<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Period standalone*<\/span><\/td>\n<td><span style=\"font-weight: 400;\">b, bb &amp; bbb<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Abbreviated<\/span><\/td>\n<td><span style=\"font-weight: 400;\">mid.<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">bbbb<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Wide<\/span><\/td>\n<td><span style=\"font-weight: 400;\">am, pm, midnight, noon, morning, afternoon, evening, night<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">bbbbb<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Narrow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">md<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hour 1-12<\/span><\/td>\n<td><span style=\"font-weight: 400;\">h<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: minimum digits<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1, 12<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">hh<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">01, 12<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hour 0-23<\/span><\/td>\n<td><span style=\"font-weight: 400;\">H<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: minimum digits<\/span><\/td>\n<td><span style=\"font-weight: 400;\">0, 23<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">HH<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">00, 23<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Minute<\/span><\/td>\n<td><span style=\"font-weight: 400;\">m<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: minimum digits<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8, 59<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">mm<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">08, 59<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Second<\/span><\/td>\n<td><span style=\"font-weight: 400;\">s<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: minimum digits<\/span><\/td>\n<td><span style=\"font-weight: 400;\">0&#8230; 59<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">ss<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">00&#8230; 59<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Fractional seconds<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 1 digit<\/span><\/td>\n<td><span style=\"font-weight: 400;\">0&#8230; 9<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">SS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 2 digits + zero padded<\/span><\/td>\n<td><span style=\"font-weight: 400;\">00&#8230; 99<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">SSS<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric: 3 digits + zero padded (= milliseconds)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">000&#8230; 999<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Zone<\/span><\/td>\n<td><span style=\"font-weight: 400;\">z, zz &amp; zzz<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Short specific non location format (fallback to O)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">GMT-8<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">zzzz<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Long specific non location format (fallback to OOOO)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">GMT-08:00<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">Z, ZZ &amp; ZZZ<\/span><\/td>\n<td><span style=\"font-weight: 400;\">ISO8601 basic format<\/span><\/td>\n<td><span style=\"font-weight: 400;\">-0800<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">ZZZZ<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Long localized GMT format<\/span><\/td>\n<td><span style=\"font-weight: 400;\">GMT-8:00<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">ZZZZZ<\/span><\/td>\n<td><span style=\"font-weight: 400;\">ISO8601 extended format + Z indicator for offset 0 (= XXXXX)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">-08:00<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">O, OO &amp; OOO<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Short localized GMT format<\/span><\/td>\n<td><span style=\"font-weight: 400;\">GMT-8<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><span style=\"font-weight: 400;\">OOOO<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Long localized GMT format<\/span><\/td>\n<td><span style=\"font-weight: 400;\">GMT-08:00<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Examples<\/h2>\n<h3>1) Basic Example<\/h3>\n<p><code>&lt;!-- Assuming myDate is a Date object in your component --&gt;<br \/>\n&lt;!-- component.html file \u2014-&gt;<\/code><\/p>\n<p>{{ myDate | date }}<\/p>\n<p>Output (depending on locale and date) default locale will be us: <strong>Jul 25, 2024<\/strong><\/p>\n<h3>2) Specifying a Format<\/h3>\n<p><code><br \/>\n{{ myDate | date: \u2018short\u2019 }}<\/code><\/p>\n<p>Output (depending on locale and date) default locale will be us<\/p>\n<p><strong> 7\/25\/24, 12:00 AM<\/strong><\/p>\n<p>Available formats include: &#8216;short&#8217;, &#8216;medium&#8217;, &#8216;long&#8217;, &#8216;full&#8217;, or a custom format like &#8216;dd\/MM\/yyyy&#8217;. Above having all the available formats and custom format you can use it as per your requirement.<\/p>\n<h3>3) Using Time Zone<\/h3>\n<p><code><!-- Assuming myDate is a Date object in your component --><br \/>\n<!-- component.html file \u2014->\n<!-- London time zone GMT+1 \u2014->\n<!-- myDate = 25-July-2024 09:58 PM \u2014-\u2192\n\n{{ myDate | date: \u2018short\u2019 : '+0100' }}<\/code>\n\nOutput will be<strong> 7\/25\/24, 05:27 PM<\/strong>\n\n\n<h3>4) Using Custom Format & Time Zone<\/h3>\n\n\n<code><!-- Assuming myDate is a Date object in your component --><br \/>\n&lt;!-- component.html file \u2014-&gt;<br \/>\n&lt;!-- London time zone GMT+1 \u2014-&gt;<br \/>\n&lt;!-- myDate = 25-July-2024 09:58 PM \u2014-\u2192<\/code><\/p>\n<p>{{ myDate | date: \u2018yyyy-MMM-dd HH:mm:ss A\u2019 : &#8216;+0100&#8217; }}<\/p>\n<p>Output will be <strong>2024\/July\/25, 05:27:30 PM<\/strong> as per london timezone<\/p>\n<h3>4) Using Custom Format &#038; Time Zone<\/h3>\n<p><code><br \/>\n{{ myDate | date: \u2018yyyy-MMM-dd HH:mm:ss A\u2019 : '+0100' }}<\/code><\/p>\n<h3>5) Locale Specific<\/h3>\n<p><code><br \/>\n{{ myDate | date: 'medium' : undefined : 'fr' }}<\/code><\/p>\n<p>Output will be <strong>25 juil. 2024 \u00e0 00:00:00<\/strong> as per french locale.<\/p>\n<p>The above pipe there is 3 argos we have passed medium for date format. <strong>Undefined<\/strong> is for passing undefined timezone &amp; last is for <strong>locale<\/strong><\/p>\n<h2>Key Points<\/h2>\n<ul>\n<li><strong>Locale:<\/strong> Determines the language and formatting rules used. It affects month and day names, symbols (like AM\/PM), and formatting conventions.<\/li>\n<li><strong>Time Zone:<\/strong> Specifies how the date and time should be adjusted based on different time zones.<\/li>\n<li><strong>Format:<\/strong> Allows customization of how the date and time are displayed. Angular provides several predefined formats, and you can also specify a custom format using predefined format strings.<\/li>\n<\/ul>\n<h2>Considerations<\/h2>\n<ul>\n<li><strong>Performance:<\/strong> DatePipe relies on Angular&#8217;s internationalization (i18n) API, which means it&#8217;s affected by Angular&#8217;s locale data and performance considerations.<\/li>\n<li><strong>Localization:<\/strong> Ensure that the locales and formats used are appropriate for your target audience to ensure a good user experience.<\/li>\n<\/ul>\n<h2>Summary<\/h2>\n<p>In summary, the Angular <strong>DatePipe<\/strong> is a powerful tool for formatting dates in Angular templates, providing flexibility through different formats, time zones, and locales to suit various application requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Angular DatePipe is a built-in pipe module that allows you to format dates in your Angular templates. It provides a convenient way to transform dates into different formats according to locale rules Syntax {{ value_expression | date[:format] [:timezone] [:locale] }} We have to import the \u201cCommon Module\u201d library in angular modules. If we use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11018,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-11016","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11016"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=11016"}],"version-history":[{"count":8,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11016\/revisions"}],"predecessor-version":[{"id":11026,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11016\/revisions\/11026"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/11018"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=11016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=11016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=11016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}