比较时间大小工具
来源:互联网 发布:java购物车代码 编辑:程序博客网 时间:2024/04/29 19:34
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 * 60 * 60 * 24); //结果是小时
}
//字符串转成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();
}
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 * 60 * 60 * 24); //结果是小时
}
//字符串转成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();
}
0 0
- 比较时间大小工具
- JS比较时间大小
- 时间大小比较
- flex比较时间大小
- js比较时间大小
- JS时间大小比较
- 时间大小的比较
- JS比较时间大小
- js 比较时间大小
- JS 比较时间大小
- java时间大小比较
- JS时间大小比较
- c#比较时间大小
- Oracle比较时间大小
- 两个时间大小比较
- js时间比较大小
- 时间大小比较
- java时间大小比较
- 手动添加 iOS 模拟器
- Javascript高级程序设计 第七章 --- 函数表达式
- Java抽象类与接口学习心得
- android activity学习
- Linux Shell 编程语法
- 比较时间大小工具
- AlertDialog使用
- tableView的属性设置解析
- 数据结构实践——用二叉树求解代数表达式
- ServletRequest,HttpServletRequest ServletResponse,ServletResponse的区别
- 统一建模UML
- Interview Summary
- srm 555
- hadoop php mapreduce