js日期时间比较大小
知识点:
new Date(Date.parse(时间1)) == new Date(Date.parse(时间2))
上面的方法可以结合自定义的时间戳 比如下面的日期时间格式化函数使用
function DateFormat() {let date = new Date(),currentDate,currentTime,seperator = "-", // 如果想要其他格式 只需 修改这里 year = date.getFullYear(),month = date.getMonth() + 1,day = date.getDate(),hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();month >= 1 && month <= 9 ? (month = "0" + month) : "";day >= 0 && day <= 9 ? (day = "0" + day) : "";//当前 日期currentDate = year + seperator + month + seperator + day;//当前 时间currentTime = hour + ":" + minute + ":" + second;// 输出格式 为 2018-8-27 14:45:33console.log(currentDate +" "+ currentTime);return currentDate;}
使用方法:
if(new Date(Date.parse(DateFormat())) == new Date(Date.parse(DateFormat()))){console.log("正确");
}else{console.log("非也");
}
js日期时间比较大小相关推荐
- JS日期时间比较大小(绝对干货)
普通日期时间比较 泛指格式相同的日期时间 var date1 = new Date("2020-3-15"); var date2 = new Date("2020-2- ...
- vue - 比较两个日期大小、比较同一天两个时间大小(判断两个日期时间的大小)JS 解决方法
介绍 vue项目中,可能需要对比两个日期时间的大小,如下代码所示: 2018-8-12 12:30 | 2018-8-12 02:30 它们谁大? 比较两个日期大小 方法一: //比较两个日期大小.格 ...
- php中日期选择代码,实现JS日期时间选择器
这次给大家带来实现JS日期时间选择器,实现JS日期时间选择器的注意事项有哪些,下面就是实战案例,一起来看一下. flatpickr 是一个轻量级.注重精益.由 UX 驱动和可扩展的 JavaScrip ...
- 【转】js日期时间函数
Date.prototype.isLeapYear 判断闰年 Date.prototype.Format 日期格式化 Date.prototype.DateAdd 日期计算 Date.prototyp ...
- JS - 日期时间比较函数
JS日期比较(yyyy-mm-dd) function duibi(a, b) {var arr = a.split("-");var starttime = new Date(a ...
- Moment JS日期时间比较
本文翻译自:Moment js date time comparison I'm using moment.js to format my date time, here I have two dat ...
- js 日期时间的格式化
将日期时间转换为指定格式,如:YYYY-mm-dd HH:MM表示2019-06-06 19:45 /*** 日期格式化* @param {*} fmt YYYY-mm-dd HH:MM 格式字符串* ...
- Oracle数据库比较日期时间的大小
在今天或者今天之前作比较: select * from JN_BUS_KJLWSBJBXX where dqsj < to_date('2007-09-07 00:00:00','yyyy-mm ...
- js 比较时间的大小
1.比较年月日 时分秒 //比较两个时间的大小 function compareTime(startTime,endTime) { var start_time = startTime.replace ...
最新文章
- HTML5之Javascript多线程
- 软件架构解读与架构师角色培养——希赛嘉宾聊天实录
- 怎么安装python的包_python下如何安装.whl包?
- 经典C语言程序100例之十三
- Important table for Fiori launchpad Designer and configuration
- 微信小程序集成腾讯云 IM SDK
- jenkins+k8s实现持续集成
- SharePoint 2013 同步FBA认证用户
- Windows XP14个小技巧
- 交运集团开设“技师工作站“ 创新“机电一体化“人才培养模式
- Excel在指定范围内匹配/查找文本(MATCH)
- sklearn神经网络/BP神经网络实现葡萄酒分类问题
- 《精通python设计模式》读书笔记之——行为型设计模式
- 根据两点经纬度计算方位角
- 四天搞懂生成对抗网络(四)——CycleGAN的绝妙设计:双向循环生成的结构
- JPress安装体验
- 浙大图灵班今年首次招生:院士授课,本科生配学业导师
- 【2015年第4期】城市交通大数据技术及智能应用系统
- 海外仓一件代发的优势有哪些?
- 在前端页面中调用本机的摄像头