📄 apf.htm
字号:
<TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">COleDateTime(WORD wDosDate)</TD> <TD ALIGN="LEFT">Copies a date time from the MS-DOS-style values WORD and wDosTime</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">COleDateTime(const SYSTEMTIME& systimeSrc)</TD> <TD ALIGN="LEFT">Copies a date time from a SYSTEMTIME structure</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">COleDateTime(const FILETIME& filetimeSrc)</TD> <TD ALIGN="LEFT">Copies a date time from a FILETIME structure</TD> </TR></TABLE></P><P>If you've constructed COleDateTime with a valid date time, the object will bemarked with a valid status flag (COleDateTime::valid). Otherwise, the status flagis invalid (COleDateTime::invalid). You can check this status by calling the GetStatus()member function to return the relevant flag value, or you can force the flag valueby passing it into the SetStatus() function.</P><P>The status flag is also updated when you set date and time values to the objectby calling the SetDateTime() function. This function takes six integer parametersfor the year (100-9999), month (1-12), day of the month (1-31), hour (0-23), minute(0-59), and second (0-59). You can also set just the date or time components by callingSetDate()--passing just the year, month, and day of the month--or by calling SetTime()--passingonly the hour, minute, and second values.</P><P>You can use the GetCurrentTime() static function to retrieve the current systemtime and set it to a COleDateTime object using the = operator overload function likethis:</P><P><PRE>COleDateTime dtCurrent;dtCurrent = COleDateTime::GetCurrentTime();</PRE><P>After running these lines, dtCurrent will be set to your machine's current systemdate and time.</P><P>The same values (in the same ranges) can be retrieved by the return value of GetYear(),GetMonth(), GetDay(), GetHour(), GetMinute(), or GetSecond(). There are also theuseful derivative functions: GetDayOfWeek() and GetDayOfYear(). GetDayOfWeek() returnsthe day of the week in the range 1 to 7 where 1 is Sunday. The GetDayOfYear() functionreturns a value in the range 1 to 366 starting at January 1.</P><P>You can retrieve a displayable formatted CString by using the Format() function.This is probably one of the most useful COleDateTime functions because you can passseveral formatting codes to specify the exact format returned from Format(), as shownin Table F.11. These codes are passed as either a string or a string resource identifier,and several individual codes are strung together to add various aspects of the formatting.</P><P>These values are also modified by the current locale settings. The locale preferencescan affect things such as the names of days and months, the ordering of MM/DD/YYrepresentations, and the AM/PM indicators.</P><P><H4>TABLE F.11. FORMATTING CODES TO FORMAT THE COleDateTime TEXT OUTPUT.</H4><P><TABLE BORDER="1"> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"><I>Code</I></TD> <TD ALIGN="LEFT"><I>Example</I></TD> <TD ALIGN="LEFT"><I>Description</I></TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%a</TD> <TD ALIGN="LEFT">Sat</TD> <TD ALIGN="LEFT">Abbreviated day of the week</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%A</TD> <TD ALIGN="LEFT">Saturday</TD> <TD ALIGN="LEFT">Day of the week</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%b</TD> <TD ALIGN="LEFT">Apr</TD> <TD ALIGN="LEFT">Abbreviated month</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%B</TD> <TD ALIGN="LEFT">April</TD> <TD ALIGN="LEFT">Month</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%c</TD> <TD ALIGN="LEFT">04/04/98 18:05:01</TD> <TD ALIGN="LEFT">Date and time in the current locale format</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%d</TD> <TD ALIGN="LEFT">04</TD> <TD ALIGN="LEFT">Day of the month (01-31)</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%H</TD> <TD ALIGN="LEFT">18</TD> <TD ALIGN="LEFT">Hour (00-23) 24 hour</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%I</TD> <TD ALIGN="LEFT">06</TD> <TD ALIGN="LEFT">Hour (01-12) 12 hour</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%j</TD> <TD ALIGN="LEFT">094</TD> <TD ALIGN="LEFT">Day of the year</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%m</TD> <TD ALIGN="LEFT">04</TD> <TD ALIGN="LEFT">Month (01-12)</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%M</TD> <TD ALIGN="LEFT">05</TD> <TD ALIGN="LEFT">Minute (01-59)</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%p</TD> <TD ALIGN="LEFT">PM</TD> <TD ALIGN="LEFT">AM/PM indicator for locale</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%S</TD> <TD ALIGN="LEFT">01</TD> <TD ALIGN="LEFT">Second (01-59)</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%U</TD> <TD ALIGN="LEFT">13</TD> <TD ALIGN="LEFT">Week of year (00-51) with Sunday as first day of week</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%w</TD> <TD ALIGN="LEFT">6</TD> <TD ALIGN="LEFT">Weekday (0-6) 0=Sunday</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%W</TD> <TD ALIGN="LEFT">13</TD> <TD ALIGN="LEFT">Week of year (00-51) with Monday as first day of week</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%x</TD> <TD ALIGN="LEFT">04/04/98</TD> <TD ALIGN="LEFT">Date in the current locale format</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%X</TD> <TD ALIGN="LEFT">18:05:01</TD> <TD ALIGN="LEFT">Time in the current locale format</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%y</TD> <TD ALIGN="LEFT">98</TD> <TD ALIGN="LEFT">Two-digit year (00-99)</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%Y</TD> <TD ALIGN="LEFT">1998</TD> <TD ALIGN="LEFT">Four-digit year (0100-9999)</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%z or %Z</TD> <TD ALIGN="LEFT">GMT Daylight Time</TD> <TD ALIGN="LEFT">Time zone name/abbreviation</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">% %</TD> <TD ALIGN="LEFT">%</TD> <TD ALIGN="LEFT">A percent sign</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%#c</TD> <TD ALIGN="LEFT">Saturday, April 04, 1998 18:05:01</TD> <TD ALIGN="LEFT">Current locale long date and time</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">%#x</TD> <TD ALIGN="LEFT">Saturday, April 04, 1998</TD> <TD ALIGN="LEFT">Current locale long date</TD> </TR></TABLE></P><P>You can use the following lines to generate a message box displaying your machine'sdate and time like this:</P><P><PRE>COleDateTime dtCurrent;dtCurrent = COleDateTime::GetCurrentTime();AfxMessageBox(dtCurrent.Format("Today is %a %b %d, %Y"));</PRE><P>When run, the time will then be displayed in a message box in the following format:</P><P><PRE>Today is Sat Apr 04, 1998</PRE><P>You can get COleDateTime to attempt to determine a date and time by calling ParseDateTime()and passing a string for it to parse and a flag value to specify that only the dateor the time component is required. ParseDateTime() will then scan the string fortime in the format HH:MM:SS, and a date in the format DD/MM/YYYY, or in a long formatsuch as January 18th, 1998. If you only want to scan for the time, you can pass VAR_TIMEVALUEONLYfor the second parameter flag value, alternatively VAR_DATEVALUEONLY for just thedate. If you don't want the users' locale preferences to be used to indicate thestring format to check for, you can pass LOCALE_NOUSEROVERRIDE as this flag value.</P><P>There are also several operator overloads you can use to add and subtract COleDateTimeSpansand to compare date and time values with other date and time values as shown in TableF.12.</P><P><H4>TABLE F.12. OPERATOR OVERLOADS USED IN COleDateTime.</H4><P><TABLE BORDER="1"> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"><I>Operator</I></TD> <TD ALIGN="LEFT"><I>Description</I></TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">=</TD> <TD ALIGN="LEFT">Copy a date/time value from another COleDateTime object, VARIANT structure, DATE structure, time_t structure, SYSTEMTIME structure, or FILETIME structure.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">+</TD> <TD ALIGN="LEFT">Add a COleDateTimeSpan value to a COleDateTime value.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">-</TD> <TD ALIGN="LEFT">Subtract a COleDateTimeSpan from a COleDateTime value or two COleDateTime objects from each other to yield a COleDateTimeSpan result.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">+=</TD> <TD ALIGN="LEFT">Add a COleDateTimeSpan value to the current COleDateTime object.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">-=</TD> <TD ALIGN="LEFT">Subtract a COleDateTimeSpan value from the current COleDateTime object.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">==</TD> <TD ALIGN="LEFT">Check whether two COleDateTime objects hold an identical date and time.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">!=</TD> <TD ALIGN="LEFT">Check whether two COleDateTime objects hold different dates and times.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"><</TD> <TD ALIGN="LEFT">Check whether one COleDateTime object is less than another.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">></TD> <TD ALIGN="LEFT">Check whether one COleDateTime object is greater than another.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"><=</TD> <TD ALIGN="LEFT">Check whether one COleDateTime object is less than or equal to another.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">>=</TD> <TD ALIGN="LEFT">Check whether one COleDateTime object is greater than or equal to another.</TD> </TR></TABLE><H3><A NAME="Heading13"></A>Using the COleDateTimeSpan Class</H3><P>A COleDateTimeSpan object can hold the difference between two COleDateTime objects.You can create one by subtracting one COleDateTime object from another or by usingone of the COleDateTimeSpan constructor forms shown in Table F.13.</P><P><H4>TABLE F.13. CONSTRUCTOR TYPES USED WITH COleDateTimeSpan.</H4><P><TABLE BORDER="1"> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT"> <H4>Constructor Definition </TD> <TD ALIGN="LEFT"> <H4>Description </TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">COleDateTimeSpan()</TD> <TD ALIGN="LEFT">Create a time span set to zero.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">COleDateTimeSpan(const COleDateTimeSpan& srcSpan)</TD> <TD ALIGN="LEFT">Copy the time span from another COleDateTimeSpan object.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">COleDateTimeSpan(long lDays, int nHours, int nMins, int nSecs)</TD> <TD ALIGN="LEFT">Initialize the time span with the passed parameter values.</TD> </TR> <TR ALIGN="LEFT" VALIGN="TOP"> <TD ALIGN="LEFT">COleDateTimeSpan(double dSpanSrc)</TD> <TD ALIGN="LEFT">Initialize the time span with the number of days passed value.</TD> </TR></TABLE></P><P>After you have a COleDateTimeSpan object, you can check or set its status usingthe GetStatus() and SetStatus() functions just like the COleDateTime object. Theonly differences are that the flag values are COleDateTimeSpan::valid and COleDateTimeSpan::invalid.</P><P>You can also set a time span by passing the number of days, hours, minutes, andseconds as integer parameters to SetDateTimeSpan(). You can then retrieve these valuesfrom a valid COleDateTimeSpan object by calling the GetDays(), GetHours(), GetMinutes(),and GetSeconds() functions that all return long values representing each portionof the time span value. If you want to retrieve the overall time span expressed indays, hours, minutes, or seconds in one double value, you can call GetTotalDays(),GetTotalHours(), GetTotalMinutes(), or GetTotalSeconds(), respectively.</P><P>You can format COleDateTimeSpan values as strings in the same way as COleDateTimevalues by passing a format string using the codes appropriate to time spans fromTable F.11.</P><P>Several operator overloads help you use COleDateTimeSpan objects arithmeticallyto add and subtract time spans to and from each other and also use them in conditions,as shown
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -