In AngularJS, you can use the following to format the date as a string:
{{ date_expression | date : format : timezone}}
filter('date')(date, format, timezone)
Where:
date:
is the date that needs to be formattedformat:
are the formatting rules (optional)timezone:
is the applied timezoneyyyy
: This is the four digit representation of year. yy
: two digit representation of year, padded (00-99). y
: one digit representation of year. MMMM
: month in year (January-December)MMM
: month in year (Jan-Dec)MM
: month in year (01-12)M
: month in year (1-12)LLLL
: stand-alone month in year (January-December)dd
: day in month (01-31)d
: day in month (1-31)EEEE
: day in Week(Sunday-Saturday)EEE
: day in Week (Sun-Sat)HH
: hour in day (00-23)H
: hour in day (0-23)hh
: hour in AM/PM (01-12)h
: hour in AM/PM (1-12)mm
: minute in hour (00-59)m
: minute in hour (0-59)ss
: second in minute (00-59)s
: second in minute (0-59)sss
: millisecond in second (000-999)a
: AM/PM markerZ
: four digit (+sign) representation of the timezone offset (-1200-+1200)ww
: week of year, padded (00-53)w
: week of year (0-53).G
, GG
, GGG
: abbreviation of era (AD
)GGGG
: long form of era (Anno Domini
)These dates can also be formatted in one of the following formats:
medium
: in the format MMM d, y h:mm:ss a
short
: in the format M/d/yy h:mm a
fullDate
: in the format EEEE, MMMM d, y for en_US locale longDate
: in the format MMMM d, y mediumDate
: in the format MMM d, y shortDate
: in the format M/d/yy
mediumTime
: in the format h:mm:ss a
shortTime
: in the format h:mm a
We can also format them using literal values; however, they need to be enclosed within single quotes e.g., “h ‘o clock’”.
For more details, refer to the official documentation.