1

I have a date objectdata = '2021-07-30T22:33:38.000Z' . I need to manipulate the string a bit, for example create a string like 'abc2021-07-30T22:33:38.000Z. If I use 'abc'+data, the result would become abcFri Jul 30 2021 15:33:38 GMT-0700 (Pacific Daylight Time)

is there a way to convert data object to a string type without changing the format?

Nevermore
  • 237
  • 2
  • 14

2 Answers2

4

You can use "abc" + data.toISOString(). By default, turning a Date instance into a string gets you a string in the form you've seen, but there are various ways of getting other formats.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • @RobG yea I chose the term badly; I meant a date that, well, looks like what they were complaining about. I'll update the answer. – Pointy Aug 03 '21 at 12:49
0

The toString() method converts a Date object to a string.

Note: This method is automatically called by JavaScript whenever a Date object needs to be displayed as a string.

 var d = new Date();
 console.log(d.toString())

more on this topic

Sam
  • 723
  • 5
  • 18