cocos2d-x 獲取系統當前時間

long NetWorkManager::currentTimeNow()  

   struct cc_timeval now; 

    CCTime::gettimeofdayCocos2d(&now, NULL); 

   struct tm *tm;

    tm = localtime(&now.tv_sec);

   int year = tm->tm_year + 1900;

   int month = tm->tm_mon + 1;

   int day = tm->tm_mday;

   int hour=tm->tm_hour;

   int minute=tm->tm_min;

   int second=tm->tm_sec;

   long millSecond=now.tv_sec * 1000 + now.tv_usec / 1000;

   std::stringstream currentTime;

    currentTime<<year<<"-"<<month<<"-"<<day<<"  "<<hour<<":"<<minute<<":"<<second<<"   "<<millSecond;

   CCLog("currentTime is %s ",currentTime.str().c_str());

   return millSecond;

發佈了28 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章