search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

純C/C++ mktime()函數 – jashliao部落格

純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);
}



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦