Postgres now() date to typescript date

Viewed 85

I have a date 2022-08-04 08:16:32.716904 // without timezone which was created with now() function in SQL as a timestamp with (6) milliseconds precision (i.e DateTime @db.Timestamp(6) with primsa).

How can I create a new Date() object in typescript to match this exact precision ?

1 Answers

You can do new Date("2022-08-04 08:16:32.716904"), it should create a date as you want to.

Another (complicated) way to do it would be to isolate all time units of your timestamp and to use this constructor new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds)

Related