Reputation: 127
To format the date, I tried prototyping a method.
Date.prototype.formatYYYYMMDDHHMMSS = function() {
return (this.getFullYear() + eval(this.getMonth() + 1)
+ this.getDate() + this.getHours() + this.getMinutes() + this.getSeconds());
};
var upload = Date.now();
var uploadDate = upload.formatYYYYMMDDHHMMSS();
But following error is shown:
upload.formatYYYYMMDDHHMMSS is not a function
Upvotes: 0
Views: 1978
Reputation: 2344
Use a date object var upload = new Date();
edit:
the ctor Date()
default is now.
Upvotes: 0
Reputation: 145438
That's because Date.now()
returns number of milliseconds elapsed since 1 January 1970 00:00:00 UTC and not a Date
object.
The correct way of using your approach would be:
var upload = new Date();
var uploadDate = upload.formatYYYYMMDDHHMMSS();
Upvotes: 2