There are currently 2 posts.
Font size: Small - 100% (Default)▼  Content converter: No conversion▼
 
Clicks Replies
1400 1
【方法】C语言用库函数获取指定日期是星期几
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 5/21/16 13:13
【代码】
#include <stdio.h>
#include <string.h> // memset函数所在头文件
#include <time.h>

void main()
{
    char *arr[] = {"日", "一", "二", "三", "四", "五", "六"}; // tm_wday为0表示星期日
    struct tm info;

    memset(&info, 0, sizeof(info)); // 将所有成员的值设为0
    info.tm_year = 2007 - 1900; // 年份必须减去1900
    info.tm_mon = 6 - 1; // 月份必须减1
    info.tm_mday = 2;
    mktime(&info);

    printf("是星期%s\n", arr[info.tm_wday]);
}

// 补充: mktime函数的返回值是UNIX时间戳, 这里不需要所以没接收

【输出】
是星期六
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 5/21/16 13:14
2007年6月2日确实是星期六
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1400 Replies: 1
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 5/21/16 13:14
Announcements