int tm_sec 秒数( 0 ~ 59 ) int tm_min 分数( 0 ~ 59 ) int tm_hour 0 時からの時間( 0 ~ 23 ) int tm_mday 月の中の日付( 1 ~ 31 ) int tm_mon 1 月からの月数( 0 ~ 11 ) int tm_year 1900 年からの年 int tm_wday 日曜からの曜日( 0 ~ 6 ) int tm_yday 1 月 1 日からの日数( 0 ~ 365 ) int tm_isdst 夏時間が有効な場合には 0 以外
#include <time.h> struct tm *localtime(const time_t *timer) timer : 格納された時間へのポインタ
#include <stdio.h>
#include <time.h>
int main()
{
struct tm *newtime;
time_t aclock;
char *now;
time(&aclock); /* 現在時刻の獲得 */
/*
asctimeを使用した出力
*/
newtime = localtime(&aclock); /* tm構造体への変換 */
now = asctime(newtime); /* 文字列への変換 */
printf("経過時間は(aclock,秒)=%ld\n", aclock);
printf("今日の日付と現在時刻は(asctime)=%s", now);
printf("メンバーの出力\n");
printf(" tm_year %d\n", newtime -> tm_year);
printf(" tm_mon %d\n", newtime -> tm_mon);
printf(" tm_mday %d\n", newtime -> tm_mday);
/*
ctimeを使用した出力
*/
now = ctime(&aclock); /* 文字列への変換 */
printf("今日の日付と現在時刻は(ctime)=%s", now);
return 0;
}
経過時間は(aclock,秒)=945656374
今日の日付と現在時刻は(asctime)=Mon Dec 20 11:19:34 1999
メンバーの出力
tm_year 99
tm_mon 11
tm_mday 20
今日の日付と現在時刻は(ctime)=Mon Dec 20 11:19:34 1999
| 菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |