最近写代码时,需要获取任意一天的起始和结束时间,0点和23:59:59这两个时间的时间戳

使用了setHours() 方法

setHours() 方法用于设置指定的时间的小时字段

1. 获取当天开始时间

moment(new Date(new Date(new Date().toLocaleDateString()).getTime()))).valueOf()

2. 获取当天结束时间

moment(new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1))).valueOf()

3. 获取任意一天的开始时间

// time为某一天的时间戳
startTime(time) {
const nowTimeDate = new Date(time)
return nowTimeDate.setHours(0, 0, 0, 0)
}

4. 获取任意一天的结束时间

endTime(time) {
const nowTimeDate = new Date(time)
return nowTimeDate.setHours(23, 59, 59, 999)
}

setHours方法地址:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours

js获取任意一天的0点和23:59:59时间的更多相关文章

  1. JS - 获取任意一天的0点和23:59:59时间

    转载自 https://www.cnblogs.com/sk-3/archive/2019/07/23/11232750.html 使用了setHours() 方法 setHours() 方法用于设置 ...

  2. js 获取 this 的属性 obj[0].getAttribute

    js  获取 this 的属性 obj[0].getAttribute

  3. js 获取前天、昨天、今天、明天、后天的时间

    js 获取前天.昨天.今天.明天.后天的时间 2011-05-19 21:03   <html><head><meta http-equiv="Content- ...

  4. JS获取任意月份的最后一天

    在获取月份天数的时候,因为月份不同,所以每个月的天数也有差异,并且由于平闰年,2月份天数也有所不同,导致程序中获取任意月份的天数十分复杂,下面就用这个方法解决此问题,调用此方法将任意年份和月份传进去, ...

  5. js 获取任意一个元素的任意一个样式属性的值

    //谷歌,火狐支持console.log(window.getComputedStyle(my$("dv"),null).left);//IE8支持console.log(my$( ...

  6. JS获取前天、昨天、今天、明天、后天的时间

    GetDateStr = function(AddDayCount) { var dd = new Date(); dd.setDate(dd.getDate()+AddDayCount);//获取A ...

  7. C# 获取某个时间的0点0分和23点59分59秒

    C#获取当月第一天和最后一天 当月第一天0时0分0秒: DateTime.Now.AddDays( - DateTime.Now.Day).Date 当月最后一天23时59分59秒: DateTime ...

  8. SQL获取当天0点0分0秒和23点59分59秒方法

    SELECT CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120)) select cast(convert(varchar(10),getdate( ...

  9. C#获取上个月的第一天零点和最后一天23点59分59秒

    //上个月第一天0点 DateTime date2 = DateTime.Now.AddMonths(-1).Date.AddDays(1 - DateTime.Now.Day);         R ...

随机推荐

  1. pytharm里面的导入上级目录飘红

    有时候导入本地模块或者py文件时,下方会出现红色的波浪线,但不影响程序的正常运行,但是在查看源函数文件时,会出现问题 问题如下: 解决方案: 1. 进入设置,找到Console下的Python Con ...

  2. HandlerMethodArgumentResolver的抽象實現AbstractNamedValueMethodArgumentResolver下的子类

    Annotation-based argument resolution 部分2 org.springframework.web.servlet.mvc.method.annotation.Reque ...

  3. IfcBuildingElement

    IfcBuildingElement /* Generated By: IFC Tools Project EXPRESS TO JAVA COMPILER: Do not edit this fil ...

  4. Dart入门

    要学Flutter必先学Dart,Dart和Java的语法很像,学过Java的人很快就能入手 Dart下载地址https://dart.dev/get-dart VSCode下载地址https://c ...

  5. 连接池-Mybatis源码

    持续更新:https://github.com/dchack/Mybatis-source-code-learn Mybatis连接池 有这么个定律,有连接的地方就有池. 在市面上,可以适配Mybat ...

  6. IDEA中Lombok插件的安装及使用

    这个插件的好处在于可以让我们的代码更简洁,减少一些重复的工作,最常用的就是@Data注解,比如在实体类上使用@Data注解,实体类的各个属性就不需要书写get和set方法. 安装方法: 1.File→ ...

  7. Python浮点数数据精度控制

    代码 import decimal from decimal import Decimal, getcontext if __name__ == '__main__': decimal.getcont ...

  8. 小技巧——解决Github项目clone慢的问题

    设置github的项目git命令走sock代理 git config --global http.https://github.com.proxy socks5://127.0.0.1:1086(so ...

  9. haproxy转发真实IP给web

    1.在haproxy.cfg中加入下面参数. option forwardfor               #如果后端服务器需要获得客户端真实ip需要配置的参数,必须要放在listen模块下 2.如 ...

  10. django:删除表后怎么重新数据迁移生成表

    1.将对应app下的migrations文件夹下面的除了__init__.py文件外全部删除 2.delete from django_migrations where app='app_name' ...