I have date format like dd.mm.yyyy
24.1.2017 00:00:00
as result I want
2017/01/24
I wrote this function to change date to format what I want.
Date.prototype.yyyymmdd = function() {
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
return [this.getFullYear(),
(mm>9 ? '' : '0') + mm,
(dd>9 ? '' : '0') + dd
].join('/');
};
var date = new Date("@Model.BeginTime");
$("#newsstart").val(date.yyyymmdd());
Problem is to convert string to date
var date = new Date("@Model.BeginTime");
This is invalid date. How can I fix this problem??
"@Model.BeginTime"is being substituted properly? You should tryvar s = "@Model.BeginTime"; console.log("date-string: %s", s); var date = new Date("@Model.BeginTime"); ...and see what is printed to the console.