js 格式化日期
Posted freddyhuang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 格式化日期相关的知识,希望对你有一定的参考价值。
//格式化日期 function formatDate(d){ var date1=new Date(d); var CurrentDate = ""; //初始化时间 var Year= date1.getFullYear();//ie火狐下都可以 var Month= date1.getMonth()+1; var Day = date1.getDate(); var Hours = date1.getHours(); var Minutes = date1.getMinutes(); var Seconds = date1.getSeconds(); CurrentDate += Year + "年"; Month >= 10 ? (CurrentDate += Month + "月"):(CurrentDate += "0" + Month + "月"); Day >= 10 ? (CurrentDate += Day +"日 "):(CurrentDate += "0" + Day+"日 "); Hours>=10 ? (CurrentDate += Hours +":"):(CurrentDate += "0"+Hours +":"); Minutes>=10 ? (CurrentDate += Minutes +":"):(CurrentDate += "0"+Minutes +":"); Seconds>=10 ? (CurrentDate += Seconds):(CurrentDate += "0"+Seconds); return CurrentDate; }
以上是关于js 格式化日期的主要内容,如果未能解决你的问题,请参考以下文章