Common operation and comparison of CTime COleDateTime

Source: Internet
Author: User
Tags datetime time interval
Common operation and comparison of CTime COleDateTime
1 to get the current time.
CTime time;
Time = Ctime::getcurrenttime ();
2) Gets the time element.
int year = time. GetYear ();
Int month = time. GetMonth ();
int day = time. Getday ();
int hour = time. Gethour ();
int minute = time. Getminute ();
int second = time. Getsecond ();
int DayOfWeek = time. GetDayOfWeek ();
3 Gets the time interval.
CTimeSpan TimeSpan (0,0,1,0); Days,hours,minutes,seconds
TimeSpan = Ctime::getcurrenttime ()-time;
4 Converts the time to a string.
CString sdate,stime,selapsed time;
Sdate = time. Format ("%m/%d/%y"); Ex:12/10/98
Stime = time. Format ("%h:%m:%s"); Ex:9:12:02
selapsed time = TimeSpan. Format ("%d:%h:%m:%s");
%d is total elapsed days
To find out more about the time format, see the strftime in the M F C document.
Using the COleDateTime class
1 Get one day of the year.
Coledate time datetime;
datetime = Coledatetime::getcurrenttime ();
int dayofyear = DateTime. Getdayofyear ();
2 reads the time from the text string.
Coledate time datetime;
Datetime. ParseDateTime ("12:12:23 January 93");
Description
CTime and COleDateTime have almost the same function. However, COleDateTime allows users to get a year
One of the day (a good way to create the Julian date), and parse a time text string.
Compared with CTime, COleDateTime's advantage is that it supports DWORD variables. COleDateTime use of
The number of digits is twice times that of a double floating-point, since CTime simply calculates the number of seconds elapsed since January 1, 1970.
Therefore to 2 0 3 7 years it would have reached 4 2 9 4 9 6 7 2 of 9 5, thereby no longer to be used. Instead
COleDateTime is a
Floating point number, which indicates that it is from 1 9 0 0 years 1 February 3 No. 0 Number of days after the day (hour is the number of days of the small parts), within thousands of years will not overflow. //------------------------------------------------------------------------------------------------------------- ---------------//

strcstring= "2003-10-27 6:24:37"; CString--->coledatetime
COleVariant vtime (strcstring);
Vtime. ChangeType (vt_date);
COleDateTime Time4=vtime;

COleDateTime time1 (1977,4,16,2,2,2); Coledatatime--->ctime
SYSTEMTIME Systime;
Varianttimetosystemtime (time1, &systime);
CTime TM (Systime);

time_t Time2=tm. GetTime (); CTime--->time_t
COleDateTime Time3 (time2); time_t--->coledatetime

CString str = Tdate.format (_t ("%y-%m-%d"));
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.