[ Pobierz całość w formacie PDF ]
.Although the format-stringconcept is the same as that used with printf(), the Format() function has its ownset of format codes, which are listed in Table F.7.Table F.7 Format Codes for the Format() FunctionCodeDescription%aDay name, abbreviated (such as Sat for Saturday)%ADay name, no abbreviation%bMonth name, abbreviated (such as Mar for March)%BMonth name, no abbreviation%cLocalized date and time (for the U.S., that would be something like 03/17/98 12:15:34)%dDay of the month as a number (01-31)%HHour in the 24-hour format (00-23)%IHour in the normal 12-hour format (01-12)%jDay of the year as a number (001-366)%mMonth as a number (01-12)%MMinute as a number (00-59)%pLocalized a.m./p.m.indicator for 12-hour clock%SSecond as a number (00-59)%UWeek of the year as a number (00-51, considering Sunday to be the first day of theweek)%wDay of the week as a number (0-6, with Sunday being 0)%WWeek of the year as a number (00-51, considering Monday to be the first day of theweek)%xLocalized date representation%XLocalized time representation%yYear without the century prefix as a number (00-99)%YYear with the century prefix as a decimal number (such as 1998)%zName of time zone, abbreviated%ZName of time zone, not abbreviated%%Percent signOther CTime member functions such as GetMinute(), GetYear(), and GetMonth() areobvious in their use.However, you may like an example of using a function like GetLocalTm(),which is what the following shows:struct tm* timeStruct;timeStruct = time.GetLocalTm();The first line of the previous code declares a pointer to a tm structure.(Thetm structure is defined by Visual C++ and shown in Listing F.14.) The second linesets the pointer to the tm structure created by the call to GetLocalTm().Listing F.14 The tm Structurestruct tm {int tm_sec; /* seconds after the minute - [0,59] */int tm_min; /* minutes after the hour - [0,59] */int tm_hour; /* hours since midnight - [0,23] */int tm_mday; /* day of the month - [1,31] */int tm_mon; /* months since January - [0,11] */int tm_year; /* years since 1900 */int tm_wday; /* days since Sunday - [0,6] */int tm_yday; /* days since January 1 - [0,365] */int tm_isdst; /* daylight saving time flag */};NOOTE: The CTime class features a number of overloaded constructors,enabling you to create CTime objects in various ways and using various times. nUsing a CTimeSpan ObjectA CTimeSpan object is nothing more complex than the difference between two times.You can use CTime objects in conjunction with CTimeSpan objects to easily determinethe amount of time that's elapsed between two absolute times.To do this, first createa CTime object for the current time.Then, when the time you're measuring has elapsed,create a second CTime object for the current time.Subtracting the old time objectfrom the new one gives you a CTimeSpan object representing the amount of time thathas elapsed.The example in Listing F.15 shows how this process works.Listing F.15 Calculating a Time SpanCTime startTime = CTime::GetCurrentTime();//.//.Time elapses.//.CTime endTime = CTime::GetCurrentTime();CTimeSpan timeSpan = endTime - startTime;© Copyright, Macmillan Computer Publishing.Allrights reserved
[ Pobierz całość w formacie PDF ]