js获取当前时间
/**
*获取当前时间,返回格式,年月日时分秒:年月日时分秒“20151124115213”;
*格式:2015-11-24 11:53:59、2015-11-24 11:54:10 267、2015-11
*/
function getDataNow() {
var date = new Date();
var yyyy = date.getFullYear();//四位年份
var month = date.getMonth() + 1;//月份 0-11
var day = date.getDate();//日
var HH = date.getHours();//时
var minute = date.getMinutes();//分钟
var second = date.getSeconds();//秒
var milliseconds = date.getMilliseconds();//毫秒
if (month < 10) {
month = "0" + month;
}
if (day < 10) {
day = "0" + day;
}
if (HH < 10) {
HH = "0" + HH;
}
if (minute < 10) {
minute = "0" + minute;
}
if (second < 10) {
second = "0" + second;
}
var time = yyyy + "-" + month + "-" + day + " " + HH + ":" + minute + ":" + second + " " + milliseconds;
var time1 = yyyy + "-" + month + "-" + day + " " + HH + ":" + minute + ":" + second;
var timeTxt = yyyy + month + day + HH + minute + second;
var ym = yyyy + "-" + month;
var ym2 = yyyy + "年" + month + "月";
var ym3 = yyyy + "年" + month + "月" + day + "日";
var ym4 = yyyy + "-" + month + "-" + day;
var time = {
DateTimeSSS: time,
TimeTxt: timeTxt,
DateTime: time1,
yyyyMM: ym,
yyyyMMT: ym2,
yyyyMMddT: ym3,
yyyyMMdd: ym4
}
return time;
}
本文转载:CSDN博客