js时间戳计算从现在时间到第二天凌晨0点0分0秒的时间
(2015-03-02 23:43:09)
标签:
股票 |
分类: js/jquery |
var hours = today.getHours();
var minutes = today.getMinutes();
var sec = today.getSeconds();
alert(hours+'小时'+minutes+'分钟'+sec+'秒')
// 今天
var today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
//alert(today);
var oneday = 1000 * 60 * 60 * 24;
// 昨天
today = today+oneday;
var yesterday = new Date(today - oneday);
//alert(yesterday);
// 上周一
var lastMonday = new Date(today- oneday * (today.getDay() +
6));
alert(lastMonday);
// 上个月1号
var lastMonthFirst = new Date(today - oneday *
today.getDate());
lastMonthFirst = new Date(lastMonthFirst - oneday *
(lastMonthFirst.getDate() - 1));
alert(lastMonthFirst);
var today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
var today = new Date("2012/11/05 24:00").getTime();
alert(today);
var now= new Date();
var year=now.getYear();
var month=now.getMonth()+1;
var day=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
alert(year+"-"+month+"-"+day+"
"+hour+":"+":"+minute+":"+second);
var jsunix = Math.round(new
Date().getTime()/1000);//获取当前时间时间戳
//alert(jsunix); //1425307045 getTime()返回数值的单位是毫秒 当前时间的时间戳 2015/3/2
22:37:25
//var test = Math.round(new Date("2012/11/05
24:00").getTime()/1000);
var test = Math.round(new Date("11/05/2012").getTime()/1000);
//1352044800
alert(test);
function MillisecondToDate(msd) {
//var nowunix = Math.round(new
Date().getTime()/1000);//获取当前时间时间戳
var nowunix = Math.round(new Date().getTime());//获取当前时间时间戳
//alert(nowunix); //1425309475 2015/3/2 23:17:55
var date = new Date();
date.setHours(23);
date.setMinutes(59);
date.setSeconds(59);
//hao = date.getTime();//本来有
//alert(hao); //1425308400031
//获取指定时间时间戳
//var secunix = Math.round(date.getTime()/1000);
var secunix = Math.round(date.getTime());
//alert(secunix); //23点59分59秒 1425312000 2015/3/3 0:0:0
shengunix = secunix-nowunix;
//alert(shengunix); //2740 2305
alert(MillisecondToDate(shengunix));