admin管理员组

文章数量:1410697

How to get year, month, day, hours, minute in milliseconds of the selected date and time in JavasScript?

var month = date.getMonth();
var day = date.getDay();
var year = date.getYear();
var hour= date.getHours();
var min= date.getMinutes();

All i want is timestamp...

How to get year, month, day, hours, minute in milliseconds of the selected date and time in JavasScript?

var month = date.getMonth();
var day = date.getDay();
var year = date.getYear();
var hour= date.getHours();
var min= date.getMinutes();

All i want is timestamp...

Share edited Mar 27, 2017 at 12:39 Sagar V 12.5k8 gold badges45 silver badges70 bronze badges asked Mar 27, 2017 at 12:23 Yogeshwar NairYogeshwar Nair 471 gold badge1 silver badge12 bronze badges 2
  • All in milliseconds ? – Pugazh Commented Mar 27, 2017 at 12:24
  • the bination of this in milliseconds and date is already given and with current time i have to create the timestamp? – Yogeshwar Nair Commented Mar 27, 2017 at 12:34
Add a ment  | 

2 Answers 2

Reset to default 2

You can do it like this:

date.getTime()

All you want to get the timestamp in milliseconds is getTime() function.

date = new Date();
console.log(date.getTime());

To get the timestamp for a particular date, pass the date and time in the format mm/dd/yyyy hh:mm to the Date constructor

date = new Date("03/27/2017 12:00");
console.log(date.getTime());

本文标签: datetimejavascript get monthyeardayhoursminute timestampStack Overflow