本文介绍了在javascript中更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的日期格式为 dd.mm.yyyy
结果我想要
我编写了此函数来更改日期以格式化所需的格式。
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");
此日期无效。
推荐答案
您可以使用库可将UTC转换为所需的格式。
You can use moment library to do convert UTC to formats you want.
您可以像关注
moment(date).format( YYYY-MM-DD);
这篇关于在javascript中更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!