zoukankan      html  css  js  c++  java
  • js比较两个时间的大小

    在工作中;我们可能会遇见比较两个时间的大小;
    这个时候;我们就可以使用比较一下两个时间的大小
    需要注意的是了解 
    
    //参考地址:  https://www.cnblogs.com/Byme/p/7687313.html
    
    function tab(date1,date2){
    	var oDate1 = new Date(date1);
    	var oDate2 = new Date(date2);
    	if(oDate1.getTime() > oDate2.getTime()){
    		console.log('第一个大');
    	} else  if(oDate1.getTime() < oDate2.getTime()){
    		console.log('第二个大');
    	}else if(oDate1.getTime() == oDate2.getTime()){
    			console.log('一样大');
    	}
    }
    tab('2015-10-10 00:00:00','2015-10-03 00:00:00');
    tab('2015-10-10','2015-10-03');
    这样的时间格式都是可以的;
    需要注意的是中间的分割符号 '-'必须是英文的;否者不能够比较;
    今天不晓得为啥,写成了中文符号,英文符号中中文符号是有区别的
    时间格式这一种,要使用英文符号
    
    
    
    new Date()参数格式如下:( 得到一个中国标准时间 )
    
    1、用整数初始化日期对象 
    var date1 = new Date(2017,06,06); console.log(date1); // Thu Jul 06 2017 00:00:00 GMT+0800 (中国标准时间) 
    var date1 = new Date(2017,1,1); console.log(date1); // Wed Feb 01 2017 00:00:00 GMT+0800 (中国标准时间) 
    var date1 = new Date(2017,01-2,01); console.log(date1); // Thu Dec 01 2016 00:00:00 GMT+0800 (中国标准时间) 
    var date1 =new Date(2017,06,06,06,06,06); console.log(date1); // Thu Jul 06 2017 06:06:06 GMT+0800 (中国标准时间) 
    说明: new Date( year, month, date, hrs, min, sec) 按给定的参数创建一日期对象
    
    2、用字符串初始化日期对象 
    var date2 = new Date(“2017/06/06”); console.log(date2); // Tue Jun 06 2017 00:00:00 GMT+0800 (中国标准时间) 
    var date2 = new Date(“2017-08-08”); console.log(date2); // Tue Aug 08 2017 08:00:00 GMT+0800 (中国标准时间) 
    var date2 = new Date(“2017-9-9”); console.log(date2); // Sat Sep 09 2017 00:00:00 GMT+0800 (中国标准时间) 
    
    
    
    
    getTime() 返回从 1970 年 1 月 1 日(指定日期)至今的毫秒数
    var d=new Date();
    document.write("从 1970/01/01 至今已过去 " + d.getTime() + " 毫秒");
    
    
    
  • 相关阅读:
    SQL Server 自动备份数据脚本
    数据库还原,System.Data.SqlClient.SqlError: 因为数据库正在使用,所以无法获得对数据库的独占访问权。 (Microsoft.SqlServer.SmoExtended)
    AD 域中给AD 用加登录本地计算的权限
    share point CSOM 客户端模式 创建表 增删改查
    .net 修改AD域中的密码
    ES6——Object.assign() 对象的合并
    nodeJs —— 从零搭建一个koa项目
    nodeJs —— mongoose学习及案例
    nodeJs —— koa 常用中间件
    js计算舍入误差解决办法
  • 原文地址:https://www.cnblogs.com/IwishIcould/p/13406219.html
Copyright © 2011-2022 走看看