<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var d2 = '2020-01-08'
var d1 = '2018-01-08'
var begintime_ms = Date.parse(new Date(d1.replace(/-/g, "/"))); //begintime 为开始时间
var endtime_ms = Date.parse(new Date(d2.replace(/-/g, "/")));   // endtime 为结束时间
console.log(begintime_ms,endtime_ms)
// 得到的结果为 毫秒数,可根据 毫秒数的大小,来判断时间。
// 当然根据毫秒数 可以根据他们的差值 来求相差的天数或是小时等。
// -------------------------------
// 以上是求得 用户输入时间的毫秒数
var date1=new Date(begintime_ms);  //开始时间
var date2=new Date(endtime_ms);    //结束时间
var date3=date2.getTime()-date1.getTime()  //时间差的毫秒数
// ------------------------------
//计算出相差天数
var days=Math.floor(date3/(24*3600*1000))
console.log(days)
//计算出小时数
var leave1=date3%(24*3600*1000)    //计算天数后剩余的毫秒数
var hours=Math.floor(leave1/(3600*1000))
//计算相差分钟数
var leave2=leave1%(3600*1000)        //计算小时数后剩余的毫秒数
var minutes=Math.floor(leave2/(60*1000))
//计算相差秒数
var leave3=leave2%(60*1000)      //计算分钟数后剩余的毫秒数
var seconds=Math.round(leave3/1000)
alert(" 相差 "+days+"天 "+hours+"小时 "+minutes+" 分钟"+seconds+" 秒")
 
 
</script>
</body>
</html>

xxxx-xx-xx的时间的加减的更多相关文章

  1. java中可以对时间进行加减处理,有时候不用在sql语句中处理

    String ssny = (String) pd.get("ssny");   SimpleDateFormat simpleDateFormat=new SimpleDateF ...

  2. 【python】详解time模块功能asctime、localtime、mktime、sleep、strptime、strftime、time等函数以及时间的加减运算

    在Python中,与时间处理相关的模块有:time.datetime以及calendar.学会计算时间,对程序的调优非常重要,可以在程序中狂打时间戳,来具体判断程序中哪一块耗时最多,从而找到程序调优的 ...

  3. MySQL 时间函数加减计算

    一.MySQL 获得当前日期时间 函数 1.1 获得当前日期 + 时间(date + time) 函数:now() mysql> select now();+———————+| now() |+ ...

  4. linux的date命令使用指定时间的加减方法与异常

    在一般网页里,date命令减时间方法为: date -d '-100 days' 我的需求是,在指定时间上减8小时.按一般理解来看,命令写成如下样子(有异常错误的写法): date -d " ...

  5. busybox date 时间的加减

    1.下载安装busybox: # wget http://busybox.net/downloads/busybox-1.29.3.tar.bz2 # tar -jxvf busybox-.tar.b ...

  6. Oracle 时间处理(加减)

    一. 类似SQL SERVER中DateAdd select sysdate,add_months(sysdate,12) from dual;        --加1年 select sysdate ...

  7. Oracle计算时间函数(对时间的加减numtodsinterval、numtoyminterval) (转)

    原文来自:http://blog.itpub.net/756652/viewspace-697256/ 11g interval分区,按天分区,需要用到函数numtodsinterval.   cre ...

  8. Oracle时间的加减

    最近三个月:  select add_months(sysdate,-3)) from dual; 最近90天:   select  to_char(sysdate-90,'yyyy-MM-dd') ...

  9. python基础——对时间进行加减

    在datetime模块中有一个timedelta这个方法,它代表两个datetime之间的时间差.. In [42]: datetime.datetime.now().strftime('%Y-%m- ...

随机推荐

  1. Validator验证框架

    Validator验证框架 系统分析 在设计Validator验证框架时,需要明确以下问题. (1)当用户没有输入数据时,弹出英文提示信息. (2)当用户输入的数据长度大于系统设置的数据长度,弹出英文 ...

  2. 微服务(Microservices)和服务网格(Service Mesh)架构概念整理

    注:文章内容为摘录性文字,自己阅读的一些笔记,方便日后查看. 微服务(Microservices) 在过去的 2016 年和 2017 年,微服务技术迅猛普及,和容器技术一起成为这两年中最吸引眼球的技 ...

  3. [BlueZ] 1、Download install and use the BlueZ and hcitool on PI 3B+

    星期日, 02. 九月 2018 11:58下午 - beautifulzzzz 1. Introduction Bluez is the default Bluetooth protocol sta ...

  4. NeuChar 平台使用及开发教程(四):使用 NeuChar 的素材服务

    各类公众号的功能之一就是为用户提供各类图文和多媒体的信息,因此素材是必不可少的. 进入 Neural Cell 设置界面,点击右侧[素材管理]按钮,进入素材管理界面. 目前系统提供了文本.多图文.图片 ...

  5. [Swift]LeetCode75. 颜色分类 | Sort Colors

    Given an array with n objects colored red, white or blue, sort them in-place so that objects of the ...

  6. [Swift]LeetCode261.图验证树 $ Graph Valid Tree

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  7. [Swift]LeetCode295. 数据流的中位数 | Find Median from Data Stream

    Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

  8. postgresql 基础sql

    创建用户和密码:crate user 用户名 with password '密码' : 创建 alter user 用户名 with password ’密码' ; 修改用户密码 查看用户信息: se ...

  9. Markdown 文档生成工具

    之前用了很多Markdown 文档生成工具,发现有几个挺好用的,现在整理出来,方便大家快速学习. loppo: 非常简单的静态站点生成器 idoc:简单的文档生成工具 gitbook:大名鼎鼎的文档协 ...

  10. RabbitMQ消息队列(六)-消息任务分发与消息ACK确认机制(.Net Core版)

    在前面一章介绍了在.Net Core中如何使用RabbitMQ,至此入门的的部分就完成了,我们内心中一定还有很多疑问:如果多个消费者消费同一个队列怎么办?如果这几个消费者分任务的权重不同怎么办?怎么把 ...