0

I want to display current time, date and date using typescript and HTML

The code I am using for javascript and HTML to print is:

const time1 = new Date(); console.log(time1.toLocaleString())

{{time1}}//in HTML

The output I get: Sun Nov 27 2022 20:26:33 GMT-0500 (Eastern Standard Time)

The output I want: Sun Nov 27 2022 20:26

I don't not want seconds or time zone

Grey Ace
  • 1
  • 1
  • Note that `.toLocaleString()` looks different based on implementation. In my brower it returns `11/27/2022, 5:42:02 PM`. For your date format you could use a replace to get rid of the trailing content: `console.log(time1.toLocaleString().replace(/:\d\d GMT.*/, ''));` – Peter Thoeny Nov 28 '22 at 01:45
  • 2
    Does this answer your question? [How do you format a Date/Time in TypeScript?](https://stackoverflow.com/questions/40526102/how-do-you-format-a-date-time-in-typescript) – Daraan Dec 02 '22 at 09:42

0 Answers0