c++
1 #include <locale.h>
2 #include <time.h>
3
4 // 获取当天0时的时间戳
5 unsigned int getStartTime()
6 {
7 time_t t = time(NULL);
8 struct tm* tm = localtime(&t);
9 tm->tm_hour = 0;
10 tm->tm_min = 0;
11 tm->tm_sec = 0;
12 return mktime(tm);
13 }
14
15 // 获取当天23:59时的时间戳
16 unsigned int getEndTime()
17 {
18 time_t t = time(NULL);
19 struct tm* tm = localtime(&t);
20 tm->tm_hour = 23;
21 tm->tm_min = 59;
22 tm->tm_sec = 59;
23 return mktime(tm);
24 }
golang
1 func getStartTime() int64 {
2 timeStr := time.Now().Format("2006-01-02")
3 timeStr += " 00:00:00"
4 formatTime, _ := time.Parse("2006-01-02 15:04:05",timeStr)
5 return formatTime.Unix();
6 }
7
8 func getEndTime() int64 {
9 timeStr := time.Now().Format("2006-01-02")
10 timeStr += " 59:59:59"
11 formatTime, _ := time.Parse("2006-01-02 15:04:05",timeStr)
12 return formatTime.Unix();
13 }
原文链接: https://www.cnblogs.com/sherlock-merlin/p/12866917.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/197242
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!