当前位置:网站首页>Golang gets the start timestamp and end timestamp of a past or future week or month
Golang gets the start timestamp and end timestamp of a past or future week or month
2022-06-24 01:12:00 【User 6786882】
Golang Get the start timestamp and end timestamp of the past or future week and month
During the development process, we often need to get the start and end timestamps of a week or a month in the future relative to the current time , The corresponding methods are prepared for you .
1. Get the start and end timestamp of a week
// Get the start and end times of a week ,week by 0 This week, ,-1 Last week, ,1 Next week and so on
func WeekIntervalTime(week int) (startTime, endTime string) {
now := time.Now()
offset := int(time.Monday - now.Weekday())
// Make a special judgment on Sunday because time.Monday = 0
if offset > 0 {
offset = -6
}
year, month, day := now.Date()
thisWeek := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
startTime = thisWeek.AddDate(0, 0, offset+7*week).Format("2006-01-02") + " 00:00:00"
endTime = thisWeek.AddDate(0, 0, offset+6+7*week).Format("2006-01-02") + " 23:59:59"
return startTime,endTime
}2. Get the start or end timestamp of a month
// Get the start and end time of a month mon by 0 This month, ,-1 Last month, ,1 And so on next month
func MonthIntervalTime(mon int) (startTime, endTime string) {
year, month, _ := time.Now().Date()
thisMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
startTime = thisMonth.AddDate(0, mon, 0).Format("2006-01-02") + " 00:00:00"
endTime = thisMonth.AddDate(0, mon+1, -1).Format("2006-01-02") + " 23:59:59"
return startTime,endTime
}边栏推荐
- numpy. linalg. Lstsq (a, B, rcond=-1) parsing
- Map design
- Shardingsphere-proxy-5.0.0 implementation of capacity range partition (V)
- JS input / output statements, variables
- [ICPR 2021] tiny object detection in aerial images
- [iccv workshop 2021] small target detection based on density map: coarse-grained density map guided object detection in aerial images
- 所见之处都是我精准定位的范畴!显著图可视化新方法开源
- Local cache selection (guava/caffeine/ohc) and performance comparison
- [machine learning] linear regression prediction
- 【CVPR 2020】会议版本:A Physics-based Noise Formation Model for Extreme Low-light Raw Denoising
猜你喜欢

阿里巴巴面试题:多线程相关

这不会又是一个Go的BUG吧?

牛学长周年庆活动:软件大促限时抢,注册码免费送!

跨域和JSONP
![Graduation project - thesis writing notes [design topic type, thesis writing details, design materials]](/img/66/c0c400609b56dd012d87c620ca66e4.png)
Graduation project - thesis writing notes [design topic type, thesis writing details, design materials]

Shardingsphere-proxy-5.0.0 implementation of capacity range partition (V)
![[ICPR 2021] tiny object detection in aerial images](/img/40/6d346f357a858f3787eeba58262801.png)
[ICPR 2021] tiny object detection in aerial images

CVPR2022 | 可精简域适应

用一个软件纪念自己故去的母亲,这或许才是程序员最大的浪漫吧

一次 MySQL 误操作导致的事故,「高可用」都顶不住了!
随机推荐
Zhongshanshan: engineers after being blasted will take off | ONEFLOW u
Law / principle / rule / rule / theorem / axiom / essence / Law
Handwritten digit recognition using SVM, Bayesian classification, binary tree and CNN
【小程序】编译预览小程序时,出现-80063错误提示
机器学习中 TP FP TN FN的概念
Real time computing framework: Flink cluster construction and operation mechanism
CODING CD
Google Earth engine (GEE) - verification results used by NDVI, NDWI and NDBI to increase classification accuracy (random forest and cart classification)
numpy. linalg. Lstsq (a, B, rcond=-1) parsing
Pad User Guide
numpy.linalg.lstsq(a,b,rcond=-1)解析
How to quickly convert stock code into int in quantitative trading?
Thread safety and lock optimization
对抗训练理论分析:自适应步长快速对抗训练
Apple iphone14 is equipped with Beidou navigation system. What are the advantages of Beidou vs GPS?
【CVPR 2022】高分辨率小目标检测:Cascaded Sparse Query for Accelerating High-Resolution Smal Object Detection
Intelligent + fault-tolerant server is the best partner in the edge computing scenario
Cross domain and jsonp
November 20, 2021: the start and end times of a movie can be listed in a small array
Solve the problem that Base64 compressed files are extracted with spaces after post request