かんたん作成【HTML CSS JavaScript PHP CGI Perl Ruby Python .htaccess】



このエントリーをはてなブックマークに追加
日時取得・表示(localtime)

#include <stdio.h>
#include <time.h>
    
void print_time(void) {
    time_t timer;
    struct tm *date;
    char str[256];
    char week[][4] = {"日", "月", "火", "水", "木", "金", "土"};

    timer = time(NULL);

    printf("%s\n", ctime(&timer));
    printf("<br><br>\n");

    date = localtime(&timer);

    printf("%s\n", asctime(date));
    printf("<br><br>\n");

    strftime(str, 255, "%x %X", date);
    printf("%s\n", str);
    printf("<br><br>\n");

    strftime(str, 255, "%Y年%m月%d日 %H時%M分%S秒", date);
    printf("%s\n", str);
    printf("<br><br>\n");

    strftime(str, 255, "%Y/%m/%d %H:%M:%S", date);
    printf("%s\n", str);
    printf("<br><br>\n");

    strftime(str, 255, "%a, %d-%b-%Y %H:%M:%S", date);
    printf("%s\n", str);
    printf("<br><br>\n");

    strftime(str, 255, "%Y, %B, %d, %A, %p%I:%M:%S", date);
    printf("%s\n", str);
    printf("<br><br>\n");

    printf("%d年%d月%d日(%s)\n", date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, week[date->tm_wday]);
    printf("<br><br>\n");

    printf("%d時%d分%d秒\n", date->tm_hour, date->tm_min, date->tm_sec);
}

int main(void) {
    printf("Content-type: text/html\n\n");
    printf("<html>\n");
    printf("<head>\n");
    printf("<title>日時</title>\n");
    printf("</head>\n");
    printf("<body>\n");
    print_time();
    printf("</body>\n");
    printf("</html>\n");
    return 0;
}
かんたん作成【HTML CSS JavaScript PHP CGI Perl Ruby Python .htaccess】