-1

In Javascript, how do I print out a date with the date and time only? If I do this,

(new Date(params['mydate'])).toString();

I get

Fri Jan 08 2021 10:57:20 GMT-0600 (Central Standard Time)

but if I try "toDateString",

(new Date(params['mydate'])).toDateString();

I don't get the time at all ...

Fri Jan 08 2021

Any way to include the time without the timezone?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • `new Date().toString().slice(0,24)` gives something like "Mon Jan 18 2021 08:29:22". – RobG Jan 17 '21 at 22:29

1 Answers1

1

Use .toLocaleDateString() and .toLocaleTimeString()

let d = new Date();
console.log(d.toLocaleDateString() + " " + d.toLocaleTimeString());
Scott Marcus
  • 64,069
  • 6
  • 49
  • 71