(转)TTime, TDateTime

转自:http://hi.baidu.com/richiechyi/blog/item/2ad4a4dd864ccc375882dd67.html

 

TTime

Location: e32std.h
Link against: euser.lib

Stores and manipulates the date and time.

It represents a date and time as a number of microseconds since midnight, January 1st, 0 AD nominal Gregorian. BC dates are represented by negative TTime values. A TTime object may be constructed from a TInt64, a TDateTime a string literal, or by default, which initialises the time to an arbitrary value. To access human-readable time information, the TTime may be converted from a TInt64 into a TDateTime, which represents the date and time as seven numeric fields and provides functions to extract these fields. Alternatively, to display the time as text, the time may be formatted and placed into a descriptor using a variety of formatting commands and which may or may not honour the system's locale settings. The conversion between time and text may be performed the other way around, so that a descriptor can be parsed and converted into a TTime value.

In addition to setting and getting the date and time and converting between text and time, TTime provides functions to get intervals between times and standard comparison and arithmetic operators which enable time intervals to be added or subtracted to or from the time.

Construction and destruction

TTime();
Constructs a TTime object. It is initialised to an arbitrary value.
TTime(const TInt64& aTime);
Constructs a TTime object from a 64-bit microsecond value.
TTime(const TDesC& aString);

Constructs a TTime object with a text string. The string consists of up to three components, any or all of which may be omitted: —

  • year, month and day, followed by a colon

  • hour, minute and second, followed by a dot

  • microsecond

When all three components are present, the string should take the form:

YYYYMMDD:HHMMSS.MMMMMM

The conversion from text to time is carried out in the same manner as that used in TTime::Set(). For a more complete description of how the string may be composed, see the description of TTime::Set().

Assignment operations

TTime& operator=(const TInt64& aTime);
TTime& operator=(const TDateTime& aDateTime);

Setting the time

TInt Set(const TDesC& aString);
void HomeTime(); //Sets the date and time of this TTime to the home time.
void UniversalTime(); //Sets the date and time of this TTime to the universal time.

Conversions to fields

TDateTime DateTime() const;
Converts a TTime object into a TDateTime object. This conversion should be carried out before the seven fields which comprise a date and time can be accessed.

Interval calculations

TTimeIntervalMicroSeconds MicroSecondsFrom(TTime aTime) const;
Calculates the number of microseconds difference between a TTime object and this TTime.

TInt SecondsFrom(TTime aTime,TTimeIntervalSeconds& aInterval) const;
Calculates the number of seconds difference between a TTime object and this TTime. The difference may be positive or negative.

TInt MinutesFrom(TTime aTime,TTimeIntervalMinutes& aInterval) const;
TInt HoursFrom(TTime aTime,TTimeIntervalHours& aInterval) const;
TTimeIntervalDays DaysFrom(TTime aTime) const;
TTimeIntervalMonths MonthsFrom(TTime aTime) const;
TTimeIntervalYears YearsFrom(TTime aTime) const;

Extracting date information

TInt WeekNoInYear() const;
TInt WeekNoInYear(TTime aStartDate) const;
TInt WeekNoInYear(TFirstWeekRule aRule) const;
TInt WeekNoInYear(TTime aStartDate,TFirstWeekRule aRule) const;
Finds the number of the current week in the year. Variants are provided which allow the user to specify the date which is to be considered as the start of the year and to determine the rule governing which week is the first week in the year.

TInt DayNoInYear() const;
TInt DayNoInYear(TTime aStartDate) const;

Gets the day number in the year. A variant exists allowing the user to set the date which is to be considered as the start of the year. If no start date is specified, the default is January 1st.

TInt DayNoInMonth() const; // Gets the day number in the month.

TDay DayNoInWeek() const;
Gets the day number within the current week, from zero to six, honouring the setting specified in TLocale::SetStartOfWeek(). By default the first day in the week is Monday.

TInt DaysInMonth() const; // Gets the number of days in the current month.

Formatting the date and time

void FormatL(TDes& aDes,const TDesC& aFormat) const;
Puts this TTime into a descriptor and formats it according to the format string specified in the second argument. Many of the formatting commands use the system's locale settings for the date and time, for instance the characters used to separate components of the date and time and the ordering of day, month and year. The list of formatting commands below is divided into two sections, the first of which lists the commands which operate without reference to the locale's date and time settings (see class TLocale) and the second table lists the commands which do use these settings.

Rounding the time

void RoundUpToNextMinute();
Rounds this TTime up to the next minute. Both the seconds and microseconds components are set to zero.

Conversion from text to date/time

TInt Parse(const TDesC& aDes,TInt aCenturyOffset=0);
Parses a descriptor containing either or both a date and time, setting this TTime to the value of the parsed descriptor.

Arithmetic operators

TTime operator+(TTimeIntervalYears aYear) const;
TTime operator+(TTimeIntervalMonths aMonth) const;
TTime operator+(TTimeIntervalDays aDay) const;
TTime operator+(TTimeIntervalHours aHour) const;
TTime operator+(TTimeIntervalMinutes aMinute) const;
TTime operator+(TTimeIntervalSeconds aSecond) const;
TTime operator+(TTimeIntervalMicroSeconds aMicroSecond) const;
TTime operator+(TTimeIntervalMicroSeconds32 aMicroSecond) const;

TTime& operator+=(TTimeIntervalYears aYear);
TTime& operator+=(TTimeIntervalMonths aMonth);
TTime& operator+=(TTimeIntervalDays aDay);
TTime& operator+=(TTimeIntervalHours aHour);
TTime& operator+=(TTimeIntervalMinutes aMinute);
TTime& operator+=(TTimeIntervalSeconds aSecond);
TTime& operator+=(TTimeIntervalMicroSeconds aMicroSecond);
TTime& operator+=(TTimeIntervalMicroSeconds32 aMicroSecond);

TTime operator-(TTimeIntervalYears aYear) const;
TTime operator-(TTimeIntervalMonths aMonth) const;
TTime operator-(TTimeIntervalDays aDay) const;
TTime operator-(TTimeIntervalHours aHour) const;
TTime operator-(TTimeIntervalMinutes aMinute) const;
TTime operator-(TTimeIntervalSeconds aSecond) const;
TTime operator-(TTimeIntervalMicroSeconds aMicroSecond) const;
TTime operator-(TTimeIntervalMicroSeconds32 aMicroSecond) const;

TTime& operator-=(TTimeIntervalYears aYear);
TTime& operator-=(TTimeIntervalMonths aMonth);
TTime& operator-=(TTimeIntervalDays aDay);
TTime& operator-=(TTimeIntervalHours aHour);
TTime& operator-=(TTimeIntervalMinutes aMinute);
TTime& operator-=(TTimeIntervalSeconds aSecond);
TTime& operator-=(TTimeIntervalMicroSeconds aMicroSecond);
TTime& operator-=(TTimeIntervalMicroSeconds32 aMicroSecond);

Comparision operators

TBool operator==(TTime aTime) const; // Tests whether two date/times are equal.

TBool operator!=(TTime aTime) const; // Tests whether two date/times are not equal.

TBool operator>=(TTime aTime) const; // Tests whether a date/time is after or is the same as another.

TBool operator<=(TTime aTime) const; // Tests whether a date/time precedes or is the same as another.

TBool operator>(TTime aTime) const; // Tests whether a date/time is after another.

TBool operator<(TTime aTime) const; // Tests whether a date/time precedes another.

Integer representation

const TInt64& Int64() const; // Gets the 64 bit integer representation of a TTime.

TDateTime

Location: e32std.h
Link against: euser.lib

Allows user access to the following components of the time: the year, month, day, hour, minute, second and microsecond, in human-readable form. These components are stored as integers and all except the year are checked for validity when a TDateTime is constructed or assigned new values.

This class only supports getting and setting the entire date/time or any component of it. It does not support adding or subtracting intervals to or from a time. For functions which manipulate times, use class TTime.

Defined in TDateTime:
Day(), Hour(), MicroSecond(), Minute(), Month(), Second(), Set(), SetDay(), SetHour(), SetMicroSecond(), SetMinute(), SetMonth(), SetSecond(), SetYear(), SetYearLeapCheck(), TDateTime(), TDateTime(), Year()

posted @ 2010-04-10 22:16  秋天的风  阅读(1032)  评论(1编辑  收藏  举报