C言語 struct tm構造体を書式付き文字列に変換 - time.h - [ strftime ]

2008.12.05 Friday | by LRESULT


struct tm構造体を書式付き文字列に変換するには、strftime()を使います。


strftime
書式 size_t strftime( char *s,
                     size_t maxsize,
                     const char *format,
                     const struct tm *stm )
機能 struct tm構造体を書式付き文字列に変換
引数 char *s : 変換した文字列の格納先
size_t maxsize : 文字列の最大バイト数
const char *format : 書式文字列
const struct tm *stm : 変換元のstruct tm構造体
戻り値 変換した文字のバイト数を返します。



書式文字列
%Y : 西暦での年数
%y : 西暦での下2桁の年数
%m : 月数[01〜12]
%B : 月の名称
%b : 月の略称
%d : 日付[01〜31]
%x : 日付(年月日)
%c : 日付(年月日)と時刻
%j : 経過日数
曜日 %w : 曜日[0〜6](0が日曜日)
%W : 経過した週[00〜53](最初が月曜日)
%A : 曜日の名称
%a : 曜日の略称
%H : 時[00〜23]
%I : 時[00〜12]
%p : 午前/午後の文字列
%M : 分[00〜59]
%S : 秒[00〜61]
%X : 時刻(00:00:00)
その他 %% : %(パーセント記号)を表示



C言語 struct tm構造体を文字列に変換 - time.h - [ asctime ]

2008.12.04 Thursday | by LRESULT


struct tm構造体を文字列に変換するには、asctime()を使います。


asctime
書式 char* asctime( struct tm *stm )
機能 struct tm構造体を文字列に変換
引数 struct tm *stm : 変換元となるstruct tm型の構造体
戻り値 変換した文字列を返します。

出力される文字列は、ctime()と同じです。
変換された文字列には、「¥n」「¥0」が追加されます。



C言語 struct tm構造体をtime_t型に変換 - time.h - [ mktime ]

2008.12.03 Wednesday | by LRESULT


struct tm構造体を time_t型に変換するには、mktime()を使います。


mktime
書式 time_t mktime( struct tm *stm )
機能 struct tm構造体を time_t型に変換
引数 struct tm *stm : 変換元となるstruct tm型の構造体
戻り値 成功すると、time_t型に変換された値を返し、
失敗すると、-1を返します。

struct tm型構造体のメンバである、曜日(tm_wday)経過日数(tm_yday)は、
  その他の年月日のメンバから計算される為、設定する必要はありません。



C言語 システム時刻をグリニッジ標準時(年月日)構造体に変換 - time.h - [ gmtime ]

2008.12.02 Tuesday | by LRESULT


ステム時刻をグリニッジ標準時の年月日構造体に変換するには、gmtime()を使います。


gmtime
書式 struct tm* gmtime( const time_t *timer )
機能 システム時刻をグリニッジ標準時用の構造体に変換
引数 const time_t *timer : time()で取得したシステム時刻
戻り値 グリニッジ標準時の struct tm型の構造体で返します。



struct tm型の構造体
int tm_sec 秒[0〜61](最大2秒のうるう秒を含む為)
int tm_min 分[0〜59]
int tm_hour 時[0〜23]
int tm_mday 日[1〜31]
int tm_mon 月[0〜11](-1された月数)
int tm_year 年(1900からの経過年数)
int tm_wday 曜日[0〜6](日:0 月:1 火:2 水:3 木:4 金:5 土:6)
int tm_yday 1月1日からの経過日数[0〜365]
int tm_isdst 夏時間の有無(0:なし 正の値:夏時間)



C言語 システム時刻を日本時間(年月日)構造体に変換 - time.h - [ localtime ]

2008.12.01 Monday | by LRESULT


ステム時刻を地域時間(日本時間)用の構造体に変換するには、localtime()を使います。

システム時刻とは、一般的にグリニッジ標準時の1970年1月1日00:00:00を
基準とした、現在までの経過時間()のことで、time()で取得します。


localtime
書式 struct tm* localtime( const time_t *timer )
機能 システム時刻を地域時間用の構造体に変換
引数 const time_t *timer : time()で取得したシステム時刻
戻り値 日本時間に変換された、struct tm型の構造体で返します。



struct tm型の構造体
int tm_sec 秒[0〜61](最大2秒のうるう秒を含む為)
int tm_min 分[0〜59]
int tm_hour 時[0〜23]
int tm_mday 日[1〜31]
int tm_mon 月[0〜11](-1された月数)
int tm_year 年(1900からの経過年数)
int tm_wday 曜日[0〜6](日:0 月:1 火:2 水:3 木:4 金:5 土:6)
int tm_yday 1月1日からの経過日数[0〜365]
int tm_isdst 夏時間の有無(0:なし 正の値:夏時間)




| 1/1PAGES |