Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'toGMTString' does not exist on type 'Date'

Tags:

typescript

I'm trying to use date function on Typescript:

let date = new Date();
let gmt = date.toGMTString();

Now error I got is:

Property 'toGMTString' does not exist on type 'Date'

So how to convert local date to GMT using typescript?

Other methods are working fine like getTime(), getDate(), etc.

like image 537
vusan Avatar asked Nov 16 '16 05:11

vusan


2 Answers

toGMTString() is deprecated, that's why it is not included in Date typings. You can use toUTCString() instead.

like image 60
Aleksey L. Avatar answered Nov 10 '22 05:11

Aleksey L.


You can simply do this:

let gmt = date['toGMTString']();
like image 1
Slava Utesinov Avatar answered Nov 10 '22 05:11

Slava Utesinov