• cocos2d 中显示系统时间


    用到的两个方法先贴上

    这个是时间回调 每分钟回去调用一次时间设置方法

     //定时更新状态栏上的时间 
     void MGameScene::update(float dt)
     {
         static float fpassedTime = 0;
         fpassedTime += dt;
         if (fpassedTime < MDZ_Seconds) return;
    
         fpassedTime = 0;
    
         //设置状态栏时间
         setStatusTime();
     }


    时间设置方法

     //设置状态栏上的时间
     void MGameScene::setStatusTime()
     {
         time_t    timeStamp = time(nullptr);
    
         auto nowDate = localtime(&timeStamp);
    
         string strTime;
    
         char timeHour[10]{0};
    
         strftime(timeHour, sizeof(timeHour), "%H:", nowDate);
    
         strTime.append(timeHour);
    
         char timeMinute[10]{0};
    
         strftime(timeMinute, sizeof(timeMinute), "%M", nowDate);
    
         strTime.append(timeMinute);
    
         //时间显示标签
         m_pTxtTime->setString(strTime);
     }

     
    %H表示获取小时 %M表示获取分钟  %Y 获取年  %m获取月 %d获取天

  • 相关阅读:
    Daily Scrum – 1/15
    Daily Scrum – 1/12
    Daily Scrum – 1/11
    Daily Scrum – 1/7
    Daily Scrum – 1/6
    Daily Scrum – 1/5
    Daily Scrum – 1/4
    1/13 update
    stand up meeting 1--11
    stand up meeting 1-6
  • 原文地址:https://www.cnblogs.com/abelmou/p/5116787.html
Copyright © 2020-2023  润新知