1.用JS获取特定格式的时间
function getdate()
{
var nowdate = new Date();
//用yyyy-MM-dd HH:mm:ss的格式输出
var year=nowdate.getFullYear();//年
var month =nowdate.getMonth()>9 ? nowdate.getMonth() : "0" + nowdate.getMonth(); //月
var day = nowdate.getDate()>9 ? nowdate.getDate() : "0"+ nowdate.getMonth(); //日
var hours =nowdate.getHours()>9 ? nowdate.getHours() : "0" + nowdate.getHours();//时
var minutes =nowdate.getMinutes()>9 ? nowdate.getMinutes() : "0" + nowdate.getMinutes();//分
var seconds =nowdate.getSeconds()>9 ? nowdate.getSeconds() : "0" + nowdate.getSeconds();//秒
var mydate = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
return mydate;
}
2.将特定字符串转换成日期
function strtodate()
{
var str ='2016-02-29 09:13:15';
str = str.replace(/-/g,"/");
var date = new Date(str);//获取日期
var time = date.getTime();//获取时间戳(毫秒)
}