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 }