0

I am looking for a date output like : "2019-05-29T06:33:33.537+05:30" - which includes gmt value. I tried to get the same by using:

var newFormat = new Date();
console.log(newFormat.toISOString());

But getting value as : 2019-06-16T03:00:27.989Z -not finds the GMT value added. What is the correct approach to get the required value?

Thanks in advance.

3gwebtrain
  • 13,401
  • 21
  • 93
  • 195
  • There is no built–in method for formatting as you require. You can write your own formatting function (not difficult) or use a formatting library, there are plenty to choose from. – RobG Jun 16 '19 at 20:36

1 Answers1

0

You can use toString():

var newFormat = new Date();
console.log(newFormat.toString());
  • toString gives you Wed Jan 23 2019 17:23:42 GMT+0800 (Singapore
    Standard Time).
  • toDateString gives you Wed Jan 23 2019.
  • toLocaleString gives you 23/01/2019, 17:23:42.
  • toLocaleDateString gives you 23/01/2019.
  • toGMTString gives you Wed, 23 Jan 2019 09:23:42 GMT.
  • toUTCString gives you Wed, 23 Jan 2019 09:23:42 GMT.
  • toISOString gives you 2019-01-23T09:23:42.079Z.
Ziv Ben-Or
  • 1,009
  • 6
  • 14