JS时间(日期)比较或相减(暂时停用)
注:此文均来自网上,可行,只供参考
//JAVASCRIPT中 日期相减很麻烦 ,现在有现成的实现方法,拷贝过去就可以用了,方便
//调用该方法(主方法)
function dateDiff(date1, date2){
var type1 = typeof date1, type2 = typeof date2;
if(type1 == 'string')
date1 = stringToTime(date1);
else if(date1.getTime)
date1 = date1.getTime();
if(type2 == 'string')
date2 = stringToTime(date2);
else if(date2.getTime)
date2 = date2.getTime();
return (date1 - date2) / 1000;//结果是秒
}
//字符串转成Time(dateDiff)所需方法
function stringToTime(string){
var f = string.split(' ', 2);
var d = (f[0] ? f[0] : '').split('-', 3);
var t = (f[1] ? f[1] : '').split(':', 3);
return (new Date(
parseInt(d[0], 10) || null,
(parseInt(d[1], 10) || 1)-1,
parseInt(d[2], 10) || null,
parseInt(t[0], 10) || null,
parseInt(t[1], 10) || null,
parseInt(t[2], 10) || null
)).getTime();
}
//调用 dateDiff("2009-10-10 19:00:00","2009-10-10 18:00:00")
返回的是秒钟
//Get days and other datetime
//diffrence two datetime
// date1 :更早的日期 小的日期
// date2 :后面的日期 大的日期
// 返回两个时间差的天数小时数分数秒数和毫秒数
function DiffLong(datestr1, datestr2) {
var date1 = new Date(Date.parse(datestr1.replace(/-/g, "/")));
var date2 = new Date(Date.parse(datestr2.replace(/-/g, "/")));
var datetimeTemp;
var isLater = true;
if (date1.getTime() > date2.getTime()) {
isLater = false;
datetimeTemp = date1;
date1 = date2;
date2 = datetimeTemp;
}
difference = date2.getTime() - date1.getTime();
thisdays = Math.floor(difference / (1000 * 60 * 60 * 24));
difference = difference - thisdays * (1000 * 60 * 60 * 24);
thishours = Math.floor(difference / (1000 * 60 * 60));
var strRet = thisdays + '天' + thishours + '小时';
return strRet;
}
JS时间(日期)比较或相减(暂时停用)的更多相关文章
- javascript 时间日期处理相加相减
var d = new Date("2008/04/15"); d.setMonth(d.getMonth() + 1 + 1);//加一个月,同理,可以加一天:getDate() ...
- javascript 时间日期处理相加,减操作方法js
javascript 时间日期处理相加,减操作方法js function dateAddDays(dataStr,dayCount){ var strdate = dataStr; // 2017年0 ...
- 关于js的当前日期的格式化,和两个日期之间的相减的天数
function getFormatYMD(timesamp){ var date = new Date(timesamp); Y = date.getFullYear() + '-'; M = (d ...
- JS时间日期
JS获取当前时间 var myDate = new Date(); myDate.get[UTC]FullYear(); //获取完整的年份(4位,1970-????)myDate.get[UT ...
- js 时间日期函数小结
Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month &quo ...
- python、js 时间日期模块time
python 参考链接:https://www.runoob.com/python/python-date-time.html 时间戳 >>> print(time.time())# ...
- JS——时间日期控件
原文:http://blog.sina.com.cn/s/blog_621768f30100qmfz.html 今天找到一个还不错的日历控件 下载地址:http://www.my97.net/dp/d ...
- js时间日期转时间戳
var contractstarttimea='2016-01-01'; var contractendtimea='2016-05-01'; var contractstart = Date.par ...
- 一款好用的JS时间日期插件layDate
觉得这个插件很不错,使用起来也很方便,推荐使用 1.插件截图 2.插件配置 选择很多,配置也很简单,插件官网:https://www.layui.com/laydate/配置说得很明确,基本操作就是: ...
随机推荐
- memory prefix un,under,uni out1
1● un 不 非,无 打开 ,解开 ,开出 2● under ʌnd ə 向下,副 的,不足的 3● uni 单一 ,单
- Python Django 前后端数据交互 之 HttpRequest、HttpResponse、render、redirect
在使用三神装的时候,首先当然是得要导入它们: from django.shortcuts import HttpResponse, render, redirect 一.HttpRequest捕获 ...
- 根据ip,实现地址信息查询接口
偶然发现的360搜索的ip查询接口,记录下: 接口地址:https://m.so.com/position 使用方式1:传ip 如访问https://m.so.com/position?ip=47.1 ...
- git操作远端分支(转)
http://www.cnblogs.com/Camier-myNiuer/p/5558884.html 原文地址:http://hi.baidu.com/lingzhixu/blog/item/4a ...
- jsp 中实现点击按钮 实现页面跳转到HTML
<input type ="button" value="跳转" onclick="window.location.href='main.htm ...
- python打包成.exe
pyuic5 mainwindow.ui -o test.py pip install pyinstaller pyinstaller -F -w ***.py https://blog.csdn.n ...
- 部署python3.6下的django
首先是安装好nginx,配置web目录,配置文件在confi.d中, server { # the port your site will be served on listen ; # the do ...
- python中几个实用的文件操作
1. 判断指定目录是否存在: os.path.exists(input_folder) 2. 判断指定目录是不是文件夹 os.path.isdir(input_folder) 3. 判断指定目录是不是 ...
- 最大似然估计和最大后验概率MAP
最大似然估计是一种奇妙的东西,我觉得发明这种估计的人特别才华.如果是我,觉得很难凭空想到这样做. 极大似然估计和贝叶斯估计分别代表了频率派和贝叶斯派的观点.频率派认为,参数是客观存在的,只是未知而矣. ...
- 如何释放vector变量
std::vector<cv::Point> probp; std::vector<int> plabel; plabel.clear(); std::vector<in ...