-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_time.cpp
More file actions
executable file
·43 lines (38 loc) · 1.9 KB
/
Copy pathcheck_time.cpp
File metadata and controls
executable file
·43 lines (38 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "check_time.h"
#include "database.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int check_time(int num) { // 传入goods_index中第num行数据
struct tm begin_tm = {
0, // 秒
goods_index[num].time_begin.tm_min, // 分钟数
goods_index[num].time_begin.tm_hour, // 小时数
goods_index[num].time_begin.tm_mday, // 当天在这个月中是第几天
goods_index[num].time_begin.tm_mon, // 当前月份是第几个月
goods_index[num].time_begin.tm_year - 1900, // 从1900年开始至今的年数
0, // 当天在本周是第几天
0, // 当天在今年是第几天
0 // 夏令时标记
};
time_t begin_tm_t = mktime(&begin_tm); // 将人类看得懂的时间转换为tick类型
struct tm end_tm = {
0, // 秒
goods_index[num].time_end.tm_min, // 分钟数
goods_index[num].time_end.tm_hour, // 小时数
goods_index[num].time_end.tm_mday, // 当天在这个月中是第几天
goods_index[num].time_end.tm_mon, // 当前月份是第几个月
goods_index[num].time_end.tm_year - 1900, // 从1900年开始至今的年数
0, // 当天在本周是第几天
0, // 当天在今年是第几天
0 // 夏令时标记
};
time_t end_tm_t = mktime(&end_tm); // 将人类看得懂的时间转换为tick类型
time_t calendar_time_t = time(NULL);
struct tm *tm_local = localtime(&calendar_time_t); // 传入本地时间
time_t now_tm_t = mktime(tm_local); // 将人类看得懂的时间转换为tick类型
if (begin_tm_t <= now_tm_t && end_tm_t >= now_tm_t) {
return 1;
}
return 0;
}