js获得当前日期,美中不足的是日期格式如果前面是个位数,则前面零不显示;
获取日期:
var myDate = new Date(); var datetime=myDate.getFullYear()+‘-‘+(myDate.getMonth()+1)+‘-‘+myDate.getDate()+‘ ‘+myDate.getHours()+‘:‘+myDate.getMinutes()+‘:‘+myDate.getSeconds(); alert(datetime);
获取时间戳:
var timestamp = (new Date()).valueOf();
日期转换时间戳:
var timestamp2 = Date.parse(new Date(vals)); vals = timestamp2 /1000;
原文地址:http://7300272.blog.51cto.com/7290272/1955534