从给定日期开始的星期几
Day of the week from a given date
我需要从给定日期找到工作日;我有以下代码但不起作用
int day;
char *str ="25/02/2014";
struct tm tm;
if (strptime(str, "%d/%m/%Y", &tm) != NULL)
{
time_t t = mktime(&tm);
day = localtime(&t)->tm_wday;
return day;
}
我在这里做错了什么?
你应该拿struct tm tm;
而不是struct tm * tm;
您需要使用 memset(&tm,0x00,sizeof(tm));
初始化tm
否则mktime
将返回 -1
> 日期 27/02/2014 的结果4
是正确的,请参阅time.h
描述
...
int tm_wday 星期几 [0,6](星期日 =0)。
星期日是0,星期一= 1,星期二= 2,星期三= 3,星期四= 4,...
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 查询SQLite数据库中的日期
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- Log4cpp:以UTC/GMT时区打印日期
- 使用C++的日期库读取时间
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 如何从头开始创建 avi 文件?
- 为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?
- 日期格式为C++
- 自一周开始以来的秒数?
- 如何在 C++20 计时中为日期添加天数?
- 一旦双簧管录制开始,主 UI 线程就会被阻止
- 如何在QTableView中排序和更改日期格式
- GStreamer在开始任何播放之前进行搜索
- 如何使用 AWS C++ 开发工具包在给定的开始和结束日期范围内列出 S3 中的文件
- 从给定日期开始的星期几
- 解析日期 41777 开始日期 01/01/1998
- 根据给定的年份和周数计算开始和结束日期/时间
- 从日期开始计算一年中的某一天
- 在c++中将dd/mm/yyyy格式的日期转换为时间戳(从01/01/1970开始的秒数)