I have UTC time in database.
I want to convert this time to local time in format dd.mm.yy h.m.s
How to do that?
My date is in UTC:
2019-08-08 08:57:59
In need local time +4:00
Just append UTC before converting:
let yourDate = new Date('08/08/2019 12:22:48 PM UTC');
yourDate.toString();
OR:
let yourDate = new Date('08/08/2019 12:22:48 UTC');
yourDate.toString();
In addition you can use pipe
which uses locale to display date in user's timezone. Try with client's timezone data::
<p>The date is {{today | date:'yyyy-MM-dd HH:mm:ss'}}</p>
Update:
For your case:
let dateString = '2019-08-08 08:57:59';
let yourDate: Date = new Date(dateString + ' UTC');
HTML:
<div>{{ today | date : 'EEEE, MMMM d, h:mm:ss' }} {{ today | date : 'a' | lowercase }}
if your time looks like '2019-08-08T08:57:59' then just concat 'z' at the end to state it as UTC then run through date pipe like
<div>{{ today+'Z' | date : 'EEEE, MMMM d, h:mm:ss' }}</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With