below code. using angular 2 build in date pipe convert time stamp proper date format.
import { component } '@angular/core'; @component({ selector: 'my-app', template:`<h1>my first angular 2 app</h1> <p>{{test | date: 'dd/mm/yyyy'}} - format: dd/mm/yyyy</p>` }) export class appcomponent { test : date = '2017-04-30t23:59:59'; }
output: 01/05/2017 - format: dd/mm/yyyy
but i'm expecting 30/04/2017 ooutput
i think running time zone issue.
from https://www.w3schools.com/js/js_dates.asp:
when setting date, without specifying time zone, javascript use browser's time zone.
when getting date, without specifying time zone, result converted browser's time zone.
when tested creating date string in constructor in jsfiddle , console logged out, getting time 5 hours later defined, correspond gmt.
try setting date timezone specified:
test : date = new date('2017-04-30t23:59:59z');
Comments
Post a Comment