js 设置当前时间的后24小时、后一小时等相对时间
不管是设置相对当前时间有多久时间差的时间,思路:先获取当前时间的时间戳,再根据需求加减时间获得新的时间戳,然后取年月日与时分秒。实例:
// 设置默认时间——先转化为毫秒数,加上 24 小时的毫秒数,再转化回来
function setTime () {
let t = new Date().getTime() + 24 * 60 * 60 * 1000; //24小时 * 60分钟 * 60秒 * 1000
let d = new Date(t);
let theMonth = d.getMonth() + 1;
let theDate = d.getDate();
let theHours = d.getHours();
let theMinutes = d.getMinutes();
if (theMonth < 10) {
theMonth = '0' + theMonth
}
if (theDate < 10) {
theDate = '0' + theDate
}
if (theHours < 10) {
theHours = '0' + theHours
}
if (theMinutes < 10) {
theMinutes = '0' + theMinutes
}
let date = d.getFullYear() + '-' + theMonth + '-' + theDate
let time = theHours + ':' + theMinutes
let Spare = date + ' ' + time
console.log(date)
console.log(time)
console.log(Spare)
}
js 设置当前时间的后24小时、后一小时等相对时间的更多相关文章
- mysql连接的空闲时间超过8小时后 MySQL自动断开该连接解决方案
在连接字符串中 添加设置节点 ConnectionLifeTime(计量单位为 秒).超过设定的连接会话 会被杀死! Connection Lifetime, ConnectionLifeTime ...
- js 实现几分钟前、几小时前、几天前,以及几分钟后、几小时后、几天前后
js 实现几分钟前.几小时前.几天前,以及几分钟后.几小时后.几天前后 /* * * 把传入的时间戳与当前时间比较,计算几分钟前.几小时前.几天前,以及几分钟后.几小时后.几天前后 * unixtim ...
- 【代码笔记】iOS-密码在进入后台1小时后重新设置
代码: AppDelegate.m #import "AppDelegate.h" #import "ViewController.h" @interface ...
- JFreeChart时间轴固定24小时每天刷新
Timeseries时间轴,设置x轴固定长度24小时 xAxis.setFixedAutoRange(3600000 * 2D), 再画出当天24点这一点 Date day = new Date(); ...
- js设置下拉框选中后change事件无效解决
下拉框部分代码: <select id="bigType"> <option value="">请选择</option> & ...
- Android系统改动时间格式为24小时制
1. frameworks/base/packages/SettingsProvider/res/values/defaults.xml 添加<stringname="time_12_ ...
- js设置时间无效的问题
在发送短信息验证码的时候要用到js设置时间倒序问题:有时候这种常规写法会导致js失效,试了很多方法才找到问题所在,可能是因为js版本过低导致. setTimeout(showT(t-1),5000) ...
- 运用JS设置cookie、读取cookie、删除cookie
JavaScript是运行在客户端的脚本,因此一般是不能够设置Session的,因为Session是运行在服务器端的.而cookie是运行在客户端的,所以可以用JS来设置cookie. 假设有这样一种 ...
- JS设置cookie
cookie 与 session 是网页开发中常用的信息存储方式.Cookie是在客户端开辟的一块可存储用户信息的地方:Session是在服务器内存中开辟的一块存储用户信息的地方. JavaScrip ...
- JS设置cookie、读取cookie、删除cookie(转载)
JavaScript是运行在客户端的脚本,因此一般是不能够设置Session的,因为Session是运行在服务器端的.而cookie是运行在客户端的,所以可以用JS来设置cookie.假设有这样一种情 ...
随机推荐
- python中字母的大小写转换
1. capitalize(): 首字母大写,其余全部小写 2. upper() :全转换成大写 3. lower(): 全转换成小写 4. title() :标题首字大写,如 &q ...
- 2018-8-14-解决-VS-跳转定义和-Resharper-重复
title author date CreateTime categories 解决 VS 跳转定义和 Resharper 重复 lindexi 2018-8-14 17:35:6 +0800 201 ...
- oracle-17113错误
Errors in file /oracle/OraHome1/admin/hncrm/udump/hncrm_ora_24470.trc: ORA-00600: internal error cod ...
- Error configuring application listener of class org.springframework.web.context.ContextLoaderListene 标签: tomcat
今天敲完ssm框架,启动tomcat时报了这个错误.如图: SEVERE: Error configuring application listener of class org.springfram ...
- WPF程序国际化
1.创建相应的xaml文件 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presen ...
- php 明天,下个星期,时间函数
例子:<?php $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now: ...
- 百度语音识别REST API用法(含JAVA代码)——不须要集成SDK的方法
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zpf8861/article/details/32329457 上一篇文章http://blog.c ...
- Java练习 SDUT-2733_小鑫の日常系列故事(二)——石头剪子布
小鑫の日常系列故事(二)--石头剪子布 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 小鑫在上幼儿园的时候,喜欢跟小伙 ...
- LeetCode115 Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S. (Hard) A subse ...
- 利用IDEA构建springboot应用-Controller的使用
Controller的使用 @Controller 处理http请求 @RestController Spring4之后新加的注解,原来返回json需要@ResponseBody配合@Contr ...