当前位置:网站首页>获取半年前当月的开始时间及当天结束时间
获取半年前当月的开始时间及当天结束时间
2022-08-08 23:32:00 【聰籽】
HTMl
<span id="body">你好</span>
<button type="button" >点击</button>
JS
function getWhatDate(str) { //有参数传递为起始时间,无参数传递为结束时间
// 获取时间戳和数据周期 // 开始时间,格式yyyy - MM - dd HH: mm: ss
var nowdate = new Date();
var halfYearDate = new Date(Date.now() - (365 / 2 * 24 * 3600 * 1000));
if (str) {
timeDate = getdate(halfYearDate, str)
} else {
timeDate = getdate(nowdate)
}
function getdate(date, str) {
// Y = date.getFullYear() + '-';
// M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
// D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
// h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
// m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
// s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
Y = date.getFullYear();
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours());
m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
if (str) {
if (M <= 11) {
return Y + '-' + (M + 1) + '-' + '01 00:00:00';
} else {
return (Y + 1) + '-' + '01-01 00:00:00';
}
} else {
return Y + '-' + M + '-' + D + ' 23:59:59';
}
}
return timeDate
}
$("button").on("click",function(){
var time = getWhatDate('start')
var end = getWhatDate()
console.log(time,end)
})
边栏推荐
- STM8L 液晶数码管驱动,温度计液晶屏显示
- WeChat applet wx:for loop output example
- 力扣每日一题-第50天-383. 赎金信
- 牛客多校2 G League of Legends
- 2022牛客多校六 B-Eezie and Pie (dfs)
- stm32 uses serial port to receive idle interrupt + dma to achieve variable length dma reception
- STM8L LCD digital tube driver, thermometer LCD display
- [GYCTF2020]Ezsqli-1|SQL注入
- (2022牛客多校五)G-KFC Crazy Thursday(二分+哈希/Manacher)
- 2022牛客多校六 M-Z-Game on grid(动态规划)
猜你喜欢
随机推荐
ABP中的数据过滤器
LightningChart .NET 10.3.2 Crack 支持旧项目直接升级
Porting ucos2 code from stm32 to GD32
(codeforce547)C-Mike and Foam(质因子+容斥原理)
Hi3516 use wifi module
-Wl,--start-group ... -Wl,--end-group 用于解决几个库的循环依赖关系
(2022牛客多校五)G-KFC Crazy Thursday(二分+哈希/Manacher)
【Bug解决】ValueError: Object arrays cannot be loaded when allow_pickle=False
最详树莓派4B装机流程及ifconfig不到wlan0的解决办法
一命令删除所有指定进程
redis集群三主三从redis-cli
51nod 2877熟练使用tarjan的知识
07 Spark on RDD 血缘关系
WeChat applet develops some function usage methods
[GYCTF2020]Ezsqli-1|SQL注入
(2022牛客多校三)A-Ancestor(LCA)
(2022杭电多校六)1012-Loop(单调栈+思维)
C语言中指针的介绍
09 Spark on RDD 阶段划分
04 Spark on 读取外部数据分区策略(源码角度分析)









