2

I need to get the date ( day of the month ) from UNIX epoch time . I can get the date from this:

new Date ().getDate()

But I need to get from Date.now(), Date.now().getDate() gives me an error..

How to get that date ( day of the month ) ??

itneg
  • 73
  • 1
  • 10

1 Answers1

2

You can pass number of miliseconds to Date constructor like:

let now = Date.now();
let date = new Date(now).getDate();
console.log(date);
mickl
  • 48,568
  • 9
  • 60
  • 89
  • Hi, I am getting this data from DB, should the milliseconds be saved as number or string? Cause I am still getting errors – itneg Dec 07 '19 at 02:11
  • @itneg did you try the number ? – mickl Dec 07 '19 at 02:11
  • i figured it out. Cause there are two formats of number in mongodb, int32 and int64, also Epoch timestamp and timestamp in milliseconds which has 3 zeros more.. Thanks for the help – itneg Dec 07 '19 at 02:31
  • unix epoch time is in seconds, not milliseconds – Jaromanda X Dec 07 '19 at 02:53