加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

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 time = parseFloat(msd) /1000;
        if (null!= time &&""!= time) {
            if (time >60&& time <60*60) {
                time = parseInt(time /60.0) +"分钟"+ parseInt((parseFloat(time /60.0) -
                parseInt(time /60.0)) *60) +"秒";
            }else if (time >=60*60&& time <60*60*24) {
                time = parseInt(time /3600.0) +"小时"+ parseInt((parseFloat(time /3600.0) -
                parseInt(time /3600.0)) *60) +"分钟"+
                parseInt((parseFloat((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60) -
                parseInt((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60)) *60) +"秒";
            }else {
                time = parseInt(time) +"秒";
            }
        }else{
            time = "0 时 0 分0 秒";
        }
        return time;

    }


//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));

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有