Elvin Mammadov Elvin Mammadov - 1 year ago 72
AngularJS Question

AngularJS datetime format get wrong hour and minute value based on localization

I have datetime value on database as follow

enter image description here

But following angularJS code display wrong hour in View

<i title="Baxıldı {{item.ViewedDate | date: 'dd.MM.yyyy hh:mm:ss Z'}}"></i>

for example:

enter image description here

I think this error depends on localization, in my country is UTC+4, so 4 hours added to current value.

Please help to solve this problem.

Answer Source

You can add timezone as the third argument when you're using the date filter.

{{ date_expression | date : format : timezone}}

Here's an example if the dates in your database in stored in UTC.

<i   title="Baxıldı {{item.ViewedDate | date: 'dd.MM.yyyy hh:mm:ss Z': 'utc'}}"></i>

From the docs:

Timezone to be used for formatting. It understands UTC/GMT and the continental US time zone abbreviations, but for general use, use a time zone offset, for example, '+0430' (4 hours, 30 minutes east of the Greenwich meridian) If not specified, the timezone of the browser will be used.