mogli mogli
mogli mogli

Reputation: 263

Convert date/time into timestamp

I want to convert following date and time, into a timestamp 13 digits. Note I use strict mode.

Date:

Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)

Time: 03:00

I tried to use Date.parse() but it was not working. What is the best way to do this?

Upvotes: 0

Views: 184

Answers (4)

Olezt
Olezt

Reputation: 1738

Create the date object, add time as you wish and then use the getTime() function:

"use strict";
var date = new Date('Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)');
date.setHours(parseInt('03'),[parseInt('00')]); //apply hours and minutes
console.log(date.toString());
console.log(date.getTime()); //use of getTime()

Upvotes: 0

alalalala
alalalala

Reputation: 889

console.log(+new Date("Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)"))

Upvotes: 0

Sophie
Sophie

Reputation: 2070

You can use the getTime function:

console.log(new Date('Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)').getTime());

Upvotes: 2

Kaustubh Khare
Kaustubh Khare

Reputation: 3510

Try below code

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

Upvotes: 1

Related Questions