CTIME Summary

xiaoxiao2021-03-05  45

Initialization

m_begintime = CTIME (2004, 1, 1, 0, 0, -1); // Parameter is Year, Month, Day, Hour, Minite, Second M_ENDTIME = CTIME :: getCurrentTime (); // Current time

2. Date comparison

CTimeSpan span;

Span = TIME1-TIME2;

Get two times intervals.

You can get span.gethai ().

3. Access database query

Use the datediff () function, specifically refer to Access Help

CSTRING TIMESQL; TIMESQL.FORMAT ("WHERE DATEDIFF ('D',% S, '% S') <= 0", "Date", M_Begintime.Format ("% Y-% M-% D");

4 Read Date Field (ODBC)

CDBVARIANT VAR; RecSet.GetfieldValue (i, var); S.Format ("% D-% D-% D", (Var.m_pdate) -> Year, (var.m_pdate) -> Month, (var.m_pdate) -> day);

5.ctime Convert to CSTRING

Example: m_begintime.format ("% Y-% M-% D"); // 2004-10-03

6.cstring Convert to CTIME

// s = "2004-10-5" int first = s.find ('-'); int.com = s.find ('-', first 1);

INT Year = ATOI (S.LEFT (4)); int MONTH = ATOI (S.MID (First 1, Second-First 1)); int days = atoi (S.MID (SECOND 1, S.Getlength () -second-1); CTIME TEMP (Year, Month, DAY, 0, 0);

7. Judge whether the correct date format of CSTRING is represented

/ / Judgment whether it is 2004-01-13 CH to represent other separators BOOL ISDATE (CSTRING STR, CHAR CH) {IF (str.isempty ()) Return False; // Date Segment Int first = str.find (CH Int second = str.find (ch, first 1);

INT Year = ATOI (Str.Left (4)); int MONTH = ATOI (Str.MID (First 1, Second-First 1)); int day = atoi (STR.MID (SECOND 1, Str.getlength () -second-1)))); // Judgment IF (Year <2000 || Year> = 2010) {Return False;} else IF (Month <1 || Month> 12) {Return False;} else <1 || Day> 31) {Return False;} else} (Month == 4 || Month == 6 || Month == 9 || Month == 11) {if (DAY> 30) {Return False; } Else {return true;}} else {== == 0 && year% 100! = 0 || Year% 400 == 0) {if (day> 29) {Return false;} else} else if (day> 28) {return false;} else {return} else {return

转载请注明原文地址:https://www.9cbs.com/read-32970.html

New Post(0)