gaurav singh
gaurav singh

Reputation: 1416

Date without time in long format

I'm able to get date in long format with time

new Date().getTime()

which return long with time

1626429691945

is it possible to return date in long without hour , minute ,seconds

Upvotes: 0

Views: 38

Answers (2)

Stephen P
Stephen P

Reputation: 14800

No. It is not possible.

Because Date.prototype.getTime() returns a long representing the number of milliseconds since the Epoch it necessarily represents a specific time.

If you want that long value the closest approximation to what you want would be to get the millisecond time of midnight of the date you want.


Nodar Sanaia's answer is a great way to get that midnight time.

Upvotes: 1

Nodar Sanaia
Nodar Sanaia

Reputation: 56

console.log(new Date(new Date().toDateString()).getTime())

Upvotes: 1

Related Questions