当前位置:网站首页>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
}边栏推荐
- 【机器学习】线性回归预测
- Real time preview of RTSP video based on webrtc
- The best Base64 encoding and decoding tutorial in the whole network, with 6 examples!
- How to view kubernetes API traffic by grabbing packets
- [OSG] OSG development (04) - create multiple scene views
- 【CVPR 2022】高分辨率小目标检测:Cascaded Sparse Query for Accelerating High-Resolution Smal Object Detection
- Apple iphone14 is equipped with Beidou navigation system. What are the advantages of Beidou vs GPS?
- ShardingSphere-proxy-5.0.0容量范围分片的实现(五)
- 这不会又是一个Go的BUG吧?
- ICML'22 | ProGCL: 重新思考图对比学习中的难样本挖掘
猜你喜欢

How to write peer-reviewed papers

Cross domain and jsonp

GNN upper edge distributor! Instead of trying to refine pills, you might as well give your GNN some tricks

【小程序】实现双列商品效果

ICML'22 | ProGCL: 重新思考图对比学习中的难样本挖掘

GNN上分利器!与其绞尽脑汁炼丹,不如给你的GNN撒点trick吧

一次 MySQL 误操作导致的事故,「高可用」都顶不住了!

Apple iphone14 is equipped with Beidou navigation system. What are the advantages of Beidou vs GPS?

Theoretical analysis of countermeasure training: adaptive step size fast countermeasure training

Shardingsphere-proxy-5.0.0 implementation of capacity range partition (V)
随机推荐
numpy. linalg. Lstsq (a, B, rcond=-1) parsing
Shengdun technology joined dragon lizard community to build a new open source ecosystem
[Hongke case] how can 3D data become operable information Object detection and tracking
GNN upper edge distributor! Instead of trying to refine pills, you might as well give your GNN some tricks
CTF steganography
jdbc
numpy.linalg.lstsq(a,b,rcond=-1)解析
Basic DDoS commands
WinSCP和PuTTY的安装和使用
【CVPR 2020】会议版本:A Physics-based Noise Formation Model for Extreme Low-light Raw Denoising
Alibaba interview question: multi thread related
Remember the performance optimization with 18 times improvement at one time
2022 postgraduate entrance examination experience sharing [preliminary examination, school selection, re examination, adjustment, school recruitment and social recruitment]
Social recruitment interview is indispensable -- 1000 interview questions for Android engineers from Internet companies
ShardingSphere-proxy-5.0.0容量范围分片的实现(五)
[applet] when compiling the preview applet, a -80063 error prompt appears
Definition of logic
The industrial Internet era will be realized by products, technologies and models derived from the industry itself
CSDN articles crawl the top ten bloggers' articles and convert them to MD
Is it safe to open an account online? What conditions need to be met?