1

I want to convert 2018-04-03T06:08:08-05:00

to

MM.dd.yyyy HH:mm

How can i do this in Angular 4.x+ ?

BadGuyKUTA
  • 210
  • 1
  • 8
  • 22

4 Answers4

1

Same as vanilla javascript using Date using getHours(), getMinutes(), and so on. Here is a reference to a similar question that may be helpful.

Current time formatting with Javascript

sjensen
  • 41
  • 6
1

Try to use:

In html:

<p>Formatted  Date: <b>{{ newdate | date:'MM.dd.yyyy HH:mm' }}</b> </p>

In component:

newdate = new Date('2018-04-03T06:08:08-05:00');

Output:

Formatted Date: 04.03.2018 22:29

Stackblitz

Shohel
  • 3,886
  • 4
  • 38
  • 75
  • Hi `newdate = new Date('2019-08-31T17:01:00'); fullDate = new Date('2019-08-31T17:01:00-05:00');` converted to `

    Formatted Date: {{ newdate | date:'h a' }} Full Date with zone difference {{fullDate | date: 'h a'}}

    ` output is : `Formatted Date: 5 PM Full Date with zone difference 3 PM` what is the difference in handling
    – Krish Aug 29 '19 at 13:14
  • @Krish, use moment js for handling your time zone – Shohel Aug 30 '19 at 10:38
0

you need to check this out : https://angular.io/api/common/DatePipe

as it says in the link you can declare a date in your component such as :

export class DatePipeComponent {
  today = Date.now();
}

and then convert it to ur desired format using pipe :

{{today | date:'yyyy-MM-dd HH:mm a z':'+0900'}}
0

these all are the multiple way you can use timezone in angular:-

{{currentDate | date:'short':'UTC +9:30 / +10:30'}}
{{currentDate | date:'short':'GMT'}}
{{currentDate | date:'short':'-0600'}}
{{currentDate | date:'short':'UTC+4'}}

date formats are given below:-

medium: Sep 9, 2019, 12:35:54 PM
long: September 9, 2019 at 12:35:54 PM GMT+5
full: Tuesday, September 9, 2019 at 12:35:54 PM GMT+05:30
shortDate: 09/3/19
mediumDate: Sep 9, 2019
longDate: September 9, 2019
fullDate: Tuesday, September 9, 2019
shortTime: 12:35 PM
mediumTime: 12:35:54 PM
longTime: 12:35:54 PM GMT+5
fullTime: 12:35:54 PM GMT+05:30

these all are the different time zone example:-

Alpha Time Zone 'UTC+1'
Arabia Standard Time 'UTC+3'
Central Standard Time 'UTC-6'
China Standard Time 'UTC+8'
Delta Time Zone 'UTC+4'
Greenwich Mean Time 'UTC+0'
Gulf Standard Time 'UTC+4'
Hawaii Standard Time 'UTC-10'
India Standard Time 'UTC+4'
Miyas Mohammed
  • 476
  • 3
  • 10