CTime CTime::Now() { CTime ret; time_t v; time(&v); struct tm* t = localtime(&v); ret.SetTime(t->tm_hour, t->tm_min, t->tm_sec); return ret; }
bool CTime::Parse(const core::string& str, CTime &tm) { std::vector<core::string> tmpArray = core::StringUtil::Split(str, mT(":")); int h = 0, m = 0, s = 0; if (tmpArray.size() == 3) { h = core::StringConverter::toInt(tmpArray[0]); m = core::StringConverter::toInt(tmpArray[1]); std::vector<core::string> arr2 = core::StringUtil::Split(tmpArray[2], mT("-"), 2); s = core::StringConverter::toInt(arr2[0]); if (arr2.size() == 2) { if (arr2[1].equals_ignore_case("PM")) h += 12; } tm.SetTime(h, m, s); return true; } if (tmpArray.size() == 2) { h = core::StringConverter::toInt(tmpArray[0]); std::vector<core::string> arr2 = core::StringUtil::Split(tmpArray[1], mT("-"), 2); m = core::StringConverter::toInt(arr2[0]); if (arr2.size() == 2) { if (arr2[1].equals_ignore_case("PM")) h += 12; } tm.SetTime(h, m, 0); return true; } return false; }