Share via


_strtime, _wstrtime

將時間複製到緩衝區。 這些函式有更安全的版本可供使用;請參閱 _strtime_s_wstrtime_s

語法

char *_strtime(
   char *timestr
);
wchar_t *_wstrtime(
   wchar_t *timestr
);
template <size_t size>
char *_strtime(
   char (&timestr)[size]
); // C++ only
template <size_t size>
wchar_t *_wstrtime(
   wchar_t (&timestr)[size]
); // C++ only

參數

timestr
時間字串。

傳回值

傳回結果字元字串 timestr 的指標。

備註

_strtime 式會將目前的當地時間複製到 所指向的 timestr 緩衝區。 時間的格式為 hh:mm:ss ,其中 hh 是兩位數,表示 24 小時標記法中的小時。 mm 是小時過去分鐘數的兩位數,而 ss 秒數為兩位數。 例如,字串 18:23:44 代表下午 6 點之後的 23 分 44 秒。緩衝區長度必須至少為 9 個位元組。

_wstrtime_strtime 的寬字元版本,_wstrtime 的引數與傳回值是寬字元字串。 除此之外,這些函式的行為相同。 如果 timestrNULL 指標,或 timestr 格式不正確,則會叫用不正確參數處理常式,如參數驗證 中所述 。 如果允許繼續例外狀況,這些函式會傳回 NULL ,如果 設定為 ,則設定 errnoEINVALNULL ,如果 timestrtimestr 格式不正確,則設定 errnoERANGE 為 。

在 C++ 中,這些函式具有樣板多載,可以叫用這些函式的更新且安全的對應版本。 如需詳細資訊,請參閱 保護範本多載

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

泛型文字常式對應

TCHAR.H 常式 _UNICODE_MBCS 未定義 _MBCS 定義 _UNICODE 定義
_tstrtime _strtime _strtime _wstrtime

需求

常式 必要的標頭
_strtime <time.h>
_wstrtime <time.h > 或 < wchar.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_strtime.c
// compile with: /W3

#include <time.h>
#include <stdio.h>

int main( void )
{
   char tbuffer [9];
   _strtime( tbuffer ); // C4996
   // Note: _strtime is deprecated; consider using _strtime_s instead
   printf( "The current time is %s \n", tbuffer );
}
The current time is 14:21:44

另請參閱

時間管理
asctime, _wasctime
ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64
gmtime, _gmtime32, _gmtime64
localtime, _localtime32, _localtime64
mktime, _mktime32, _mktime64
time, _time32, _time64
_tzset