Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 2 date pipe add or sub hour

I have a problem about new Angular 2 Date Pipe.

I have a date value which is;

let myDate = '2017-01-31T17:53:36'

And I use Date Pipe as formatter to display in view like this;

{{myDate | date: 'dd/MM/yyyy HH:mm' }}

But it shows me the local time which is adding +3 hour.

31/01/2017 20:53

I would like to show which exact time is;

31/01/2017 17:53

How can I do this?

like image 329
İsmail Şener Avatar asked Aug 11 '26 21:08

İsmail Şener


1 Answers

Hope it will help: https://www.reddit.com/r/Angular2/comments/4so1j7/how_to_set_locale_for_datepipe/

This is a pipe, there for you use it in your template. Basically in my case, my webApi returns full date format (ie. Tue Dec 15 2015 13:30:32 GMT-0500 (Eastern Standard Time)). So in my pipe I do new Date(value) which will create a javascript Date object from the string. If your date returned from the http call doesn't contain any localisation information, then the parsed date will be taken like if it was in your current timezone.

like image 183
Sargon Avatar answered Aug 13 '26 11:08

Sargon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!