获取系统时间!

const char* SetLayer::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 currentTime.str().c_str();

}

 

posted @ 2013-06-03 18:44  六界剑仙  阅读(98)  评论(0)    收藏  举报