Reputation: 55
When I use
var today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());
I get that today
is Tue Jan 14 00:00:00 GMT+02:00 2020
If I do today.toDateString()
then I get Tue Jan 14 2020
If I store the last result to a cell how can I convert it back to what it was? (Date
object)
Upvotes: 1
Views: 46
Reputation: 5201
Yes, there are 4 ways to create a new Date
object in JavaScript:
new Date()
new Date(year, month, day, hours, minutes, seconds, milliseconds)
new Date(milliseconds)
new Date(date string)
The last one solves your problem:
let now = new Date();
let today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
console.log(today);
let today2 = new Date(today.toString());
console.log(today2);
Upvotes: 1
Reputation: 2252
Try like below,
let today = new Date();
let todayInString = today.toDateString();
let originalDateForm = new Date(todayInString);
console.log(originalDateForm)
Upvotes: 1