1.获取当前时间戳(ms)
var timestamp=Date.parse(new Date())
var timestamp=new Date().getTime()
var timestamp=(new Date()).valueOf()
2.获取某个时间格式的时间戳和倒计时
var stringtime1='2017-04-01 17:02:08'
var stringtime2='2017-05-01 8:02:01'
var timestamp=Date.parse(new Date(stringtime));
var daltatime=timestamp2-timestamp1;
var iS=parseInt(daltatime/1000)
var iD=parseInt(iS/86400) //天数
iS %= 86400 //剩余的秒数->转化成小时
var iH=parseInt(iS/3600) //小时
iS %=3600
var iM=parseInt(iS/60) //分钟
iS %=60 //秒数
3.将时间戳转换成时间格式字符串
var timestamp=1491816429000
var newDate= new Date()
newDate.setTime(timestamp)
1.console.log(newDate.toDateString()) //Mon Apr 10 2017 typeof---->string
2.console.log(newDate.toLocaleDateString()) //2017-4-10
3.console.log(newDate.toLocaleTimeString()) //17:27:09
link:http://www.cnblogs.com/yjf512/p/3796229.html
4.
//获取时间
var oDate= new Date()
var iY=oDate.getFullYear()
var iMon=oDate.getMonth() //0-11
var iDa=oDate.getDate()
var iH=oDate.getHours()
var iM=oDate.getMinutes()
var iS=oDate.getSeconds()
var iSm=oDate.getMilliSeconds()
var iD=oDate.getDay() //0-6 0-->星期日
//设置时间
oDate.setFullYear(iY,iMon,iDa)
oDate.setHours(iH,iM,iS,iSm)