Zi 字媒體
2017-07-25T20:27:27+00:00
純C/C++ mktime()函數
資料來源: http://www.w3big.com/zh-TW/cplusplus/c-function-mktime.html
線上編譯器: https://www.tutorialspoint.com/compile_c_online.php
time_t mktime(struct tm *timeptr)函數,把timeptr所指向的結構轉換為一個依據本地時區的time_t值
code:
#include
#include
#define BST (+1)
#define CCT (+8)
int main ()
{
time_t rawtime;
struct tm *info;
int ret;
char buffer[80];
time(&rawtime);
/* 获取 GMT 时间 */
info = gmtime(&rawtime );
ret = mktime(info);
if( ret == -1 )
{
printf("错误:不能使用 mktime 转换时间。\n");
}
else
{
strftime(buffer, sizeof(buffer), "%c", info );
printf(buffer);
}
printf("当前的世界时钟:\n");
printf("伦敦:-:d\n", (info->tm_hour+BST)$, info->tm_min);
printf("中国:-:d\n", (info->tm_hour+CCT)$, info->tm_min);
return(0);
}
寫了
5860316篇文章,獲得
23313次喜歡