0

I am new to Node Js I am using Date.now() to get the timestamp of current time
But i wanted the timestamp value of only current date not including the time.
For Example
Now current time is August 9, 2017 8:19:28 PM and the timestamp will be 1502309968000 But I want timestamp of only August 9, 2017 12:00:00 AM and the timestamp will be 1502236800000
How to solve this ?

Rudresh
  • 75
  • 3
  • 13

3 Answers3

4

Create a date object, and set hours, minutes, seconds and milliseconds to zero

var date = new Date();

date.setHours(0,0,0,0);

var time = date.getTime();

console.log(time);

Note that setHours accepts minutes, seconds etc. as well.

.setHours(hoursValue[, minutesValue[, secondsValue[, msValue]]])

adeneo
  • 312,895
  • 29
  • 395
  • 388
1

just set the Hours to 0

d = new Date();
d.setHours(0,0,0,0);
Daniel Miron
  • 460
  • 3
  • 14
0

Try http://momentjs.com/ It will give you the format that you needed.

enter image description here

Pak Chu
  • 253
  • 1
  • 5
  • 13