首页 > 编程知识 正文

datetime转换为年月日格式,date 时间格式

时间:2023-05-04 15:51:19 阅读:263334 作者:708

这个没什么好讲的,就是在总结常用的代码片段,兄弟们需要的话就直接拿去用,代码如下:

function FormatToDate(val) { if (val != null) { var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10)); //月份为0-11,所以+1,月份小于10时补个0 var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); return date.getFullYear() + "-" + month + "-" + currentDate; } return "";}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。