bool CDateTime::ParseStepThird(string text) { if(parseYMD(text)){ getHMS(text); //此处不考虑时分秒是否得到。如:2005 may 5 this->sStamp = mktime(sTm); return true; } return false; }
QString Functions::timeToStr( int t, bool space ) { if ( t < 0 ) return QString(); QString separator; if ( space ) separator = " : "; else separator = ":"; int h, m, s; getHMS( t, h, m, s ); QString timStr; if ( h ) timStr = QString( "%1" + separator ).arg( h, 2, 10, QChar( '0' ) ); timStr += QString( "%1" + separator + "%2" ).arg( m, 2, 10, QChar( '0' ) ).arg( s, 2, 10, QChar( '0' ) ); return timStr; }
bool CDateTime::ParseDateTime(const char *timeinputstr,const char *format) { if(timeinputstr == NULL || ::strlen(timeinputstr) ==0) return false; string timeinput(timeinputstr),strtime; if(format != NULL) { string pattern(format); bool ret = parseFormatDate(timeinput,pattern); if(ret) return true; } strtime = timeinput; char *str = (char *)malloc(strtime.length()+1); if(str){ char *strtmp = str; ReplaceSpace(strtime,"点","时"); str[0] = 0; if(FilteTag(strtime.c_str(),str)){ strtime = str; ReplaceSpace(strtime,NULL," "); if(strtime.empty()) { free(strtmp); return false; } if(defaultparse(strtime.c_str())) { free(strtmp); return true; }else if(ParseStepFirst(strtime)){ free(strtmp); return true; }else if(ParseStepSecond(strtime)){ free(strtmp); return true; }else if(ParseStepThird(strtime)){ free(strtmp); return true; }else if(ParseSteFourth(strtime.c_str())){ free(strtmp); return true; }else if(ParseSteFifth(strtime.c_str())){ free(strtmp); return true; }else{ if(getHMS(strtime)){ sTm->tm_year = sYear; sTm->tm_mon = sMonth; sTm->tm_mday = sDay; free(strtmp); return true; } free(strtmp); return false; } } else { free(strtmp); return false; } } return false; }