1

I have date value from postgres db without timezone. I want this display in angular 2 template with timezone and locale

postgres db value : 2017-11-14 09:40:59.753

I just displayed date in angular template using {{codeset.created_on}} it will be displayed below like :

Tue Nov 14 2017 09:40:59 GMT+0530 (IST)

But I want display current time based on timezone with locale

I tried like below in angular template :

<span>{{codeset.created_on | date :'dd/MM/yyyy h:mm a' :'+530' :'en-US'}}</span>
Nour
  • 1,458
  • 1
  • 18
  • 27
Chandru
  • 10,864
  • 6
  • 38
  • 53
  • Old question but I had a similar problem. Hope the following help someone in the future because it took me a while to figure out. I used Angular 7 but the DatePipe format is the same. When my application parsed JSON -response from API, the date-time strings not included a timezone. So then angular parsed date-strings to local time already. My fix was to use the following response format in API endpoints: `2019-07-31T14:00:00Z` Simple fix but was hard to figure out. After that, template pipe parameters worked well because not it was converted first to UTC timezone. – T.Nylund Jul 30 '19 at 20:44

1 Answers1

2

You can set it globally by providing LOCALE_ID to your app. In your app.module.ts for example:

import { LOCALE_ID } from '@angular/core';

@NgModule({
  declarations: [ ... ],
  imports: [ ... ],
  providers: [
    ...
    { provide: LOCALE_ID, useValue: 'nl-NL' }
  ],
  bootstrap: [ AppComponent ],
})
Gideon
  • 1,954
  • 3
  • 22
  • 29
  • It is another possibility but not the solution he is asking for. He wants to put the locale in the template. – Sytham Sep 19 '18 at 10:27