代码如下:
timechina(timestamp) {
if (timestamp) {
var time = new Date(timestamp);
var y = time.getFullYear(); //getFullYear方法以四位数字返回年份
var M = time.getMonth() + 1; // getMonth方法从 Date 对象返回月份 (0 ~ 11),返回结果需要手动加一
var d = time.getDate(); // getDate方法从 Date 对象返回一个月中的某一天 (1 ~ 31)
return y+'年'+M+'月'+d+'日'
} else {
return '';
}
}
timestamp就是要转换的日期:如2025-05-11
上一篇:
处理文字溢出,带省略号和不带省略号
下一篇:
javascript对汉字的编码和解码