Time Class Reference

Holds an absolute date and time. More...

List of all members.

Public Member Functions

 Time () throw ()
 Creates a Time object.
 Time (const Time &other) throw ()
 Creates a copy of another Time object.
 Time (int64 millisecondsSinceEpoch) throw ()
 Creates a time based on a number of milliseconds.
 Time (int year, int month, int day, int hours, int minutes, int seconds=0, int milliseconds=0, bool useLocalTime=true) throw ()
 Creates a time from a set of date components.
 ~Time () throw ()
 Destructor.
Timeoperator= (const Time &other) throw ()
 Copies this time from another one.
int64 toMilliseconds () const throw ()
 Returns the time as a number of milliseconds.
int getYear () const throw ()
 Returns the year.
int getMonth () const throw ()
 Returns the number of the month.
const String getMonthName (bool threeLetterVersion) const throw ()
 Returns the name of the month.
int getDayOfMonth () const throw ()
 Returns the day of the month.
int getDayOfWeek () const throw ()
 Returns the number of the day of the week.
const String getWeekdayName (bool threeLetterVersion) const throw ()
 Returns the name of the weekday.
int getHours () const throw ()
 Returns the number of hours since midnight.
bool isAfternoon () const throw ()
 Returns true if the time is in the afternoon.
int getHoursInAmPmFormat () const throw ()
 Returns the hours in 12-hour clock format.
int getMinutes () const throw ()
 Returns the number of minutes, 0 to 59.
int getSeconds () const throw ()
 Returns the number of seconds, 0 to 59.
int getMilliseconds () const throw ()
 Returns the number of milliseconds, 0 to 999.
bool isDaylightSavingTime () const throw ()
 Returns true if the local timezone uses a daylight saving correction.
const String getTimeZone () const throw ()
 Returns a 3-character string to indicate the local timezone.
const String toString (bool includeDate, bool includeTime, bool includeSeconds=true, bool use24HourClock=false) const throw ()
 Quick way of getting a string version of a date and time.
const String formatted (const String &format) const throw ()
 Converts this date/time to a string with a user-defined format.
const Time operator+ (const RelativeTime &delta) const throw ()
 Adds a RelativeTime to this time and returns the result.
const Time operator- (const RelativeTime &delta) const throw ()
 Subtracts a RelativeTime from this time and returns the result.
const RelativeTime operator- (const Time &other) const throw ()
 Returns the relative time difference between this time and another one.
bool operator== (const Time &other) const throw ()
 Compares two Time objects.
bool operator!= (const Time &other) const throw ()
 Compares two Time objects.
bool operator< (const Time &other) const throw ()
 Compares two Time objects.
bool operator<= (const Time &other) const throw ()
 Compares two Time objects.
bool operator> (const Time &other) const throw ()
 Compares two Time objects.
bool operator>= (const Time &other) const throw ()
 Compares two Time objects.
bool setSystemTimeToThisTime () const throw ()
 Tries to set the computer's clock.

Static Public Member Functions

static const Time JUCE_CALLTYPE getCurrentTime () throw ()
 Returns a Time object that is set to the current system time.
static const String getWeekdayName (int dayNumber, bool threeLetterVersion) throw ()
 Returns the name of a day of the week.
static const String getMonthName (int monthNumber, bool threeLetterVersion) throw ()
 Returns the name of one of the months.
static int64 currentTimeMillis () throw ()
 Returns the current system time.
static uint32 getMillisecondCounter () throw ()
 Returns the number of millisecs since system startup.
static double getMillisecondCounterHiRes () throw ()
 Returns the number of millisecs since system startup.
static void waitForMillisecondCounter (uint32 targetTime) throw ()
 Waits until the getMillisecondCounter() reaches a given value.
static uint32 getApproximateMillisecondCounter () throw ()
 Less-accurate but faster version of getMillisecondCounter().
static int64 getHighResolutionTicks () throw ()
 Returns the current high-resolution counter's tick-count.
static int64 getHighResolutionTicksPerSecond () throw ()
 Returns the resolution of the high-resolution counter in ticks per second.
static double highResolutionTicksToSeconds (int64 ticks) throw ()
 Converts a number of high-resolution ticks into seconds.
static int64 secondsToHighResolutionTicks (double seconds) throw ()
 Converts a number seconds into high-resolution ticks.

Detailed Description

Holds an absolute date and time.

Internally, the time is stored at millisecond precision.

See also:
RelativeTime

Constructor & Destructor Documentation

Time::Time (  )  throw ()

Creates a Time object.

This default constructor creates a time of 1st January 1970, (which is represented internally as 0ms).

To create a time object representing the current time, use getCurrentTime().

See also:
getCurrentTime
Time::Time ( const Time other  )  throw ()

Creates a copy of another Time object.

Time::Time ( int64  millisecondsSinceEpoch  )  throw ()

Creates a time based on a number of milliseconds.

The internal millisecond count is set to 0 (1st January 1970). To create a time object set to the current time, use getCurrentTime().

Parameters:
millisecondsSinceEpoch the number of milliseconds since the unix 'epoch' (midnight Jan 1st 1970).
See also:
getCurrentTime, currentTimeMillis
Time::Time ( int  year,
int  month,
int  day,
int  hours,
int  minutes,
int  seconds = 0,
int  milliseconds = 0,
bool  useLocalTime = true 
) throw ()

Creates a time from a set of date components.

The timezone is assumed to be whatever the system is using as its locale.

Parameters:
year the year, in 4-digit format, e.g. 2004
month the month, in the range 0 to 11
day the day of the month, in the range 1 to 31
hours hours in 24-hour clock format, 0 to 23
minutes minutes 0 to 59
seconds seconds 0 to 59
milliseconds milliseconds 0 to 999
useLocalTime if true, encode using the current machine's local time; if false, it will always work in GMT.
Time::~Time (  )  throw ()

Destructor.


Member Function Documentation

Time& Time::operator= ( const Time other  )  throw ()

Copies this time from another one.

static const Time JUCE_CALLTYPE Time::getCurrentTime (  )  throw () [static]

Returns a Time object that is set to the current system time.

See also:
currentTimeMillis

Referenced by CarbonViewWrapperComponent::createWindow(), and CarbonViewWrapperComponent::timerCallback().

int64 Time::toMilliseconds (  )  const throw ()

Returns the time as a number of milliseconds.

Returns:
the number of milliseconds this Time object represents, since midnight jan 1st 1970.
See also:
getMilliseconds
int Time::getYear (  )  const throw ()

Returns the year.

A 4-digit format is used, e.g. 2004.

int Time::getMonth (  )  const throw ()

Returns the number of the month.

The value returned is in the range 0 to 11.

See also:
getMonthName
const String Time::getMonthName ( bool  threeLetterVersion  )  const throw ()

Returns the name of the month.

Parameters:
threeLetterVersion if true, it'll be a 3-letter abbreviation, e.g. "Jan"; if false it'll return the long form, e.g. "January"
See also:
getMonth
int Time::getDayOfMonth (  )  const throw ()

Returns the day of the month.

The value returned is in the range 1 to 31.

int Time::getDayOfWeek (  )  const throw ()

Returns the number of the day of the week.

The value returned is in the range 0 to 6 (0 = sunday, 1 = monday, etc).

const String Time::getWeekdayName ( bool  threeLetterVersion  )  const throw ()

Returns the name of the weekday.

Parameters:
threeLetterVersion if true, it'll return a 3-letter abbreviation, e.g. "Tue"; if false, it'll return the full version, e.g. "Tuesday".
int Time::getHours (  )  const throw ()

Returns the number of hours since midnight.

This is in 24-hour clock format, in the range 0 to 23.

See also:
getHoursInAmPmFormat, isAfternoon
bool Time::isAfternoon (  )  const throw ()

Returns true if the time is in the afternoon.

So it returns true for "PM", false for "AM".

See also:
getHoursInAmPmFormat, getHours
int Time::getHoursInAmPmFormat (  )  const throw ()

Returns the hours in 12-hour clock format.

This will return a value 1 to 12 - use isAfternoon() to find out whether this is in the afternoon or morning.

See also:
getHours, isAfternoon
int Time::getMinutes (  )  const throw ()

Returns the number of minutes, 0 to 59.

int Time::getSeconds (  )  const throw ()

Returns the number of seconds, 0 to 59.

int Time::getMilliseconds (  )  const throw ()

Returns the number of milliseconds, 0 to 999.

Unlike toMilliseconds(), this just returns the position within the current second rather than the total number since the epoch.

See also:
toMilliseconds
bool Time::isDaylightSavingTime (  )  const throw ()

Returns true if the local timezone uses a daylight saving correction.

const String Time::getTimeZone (  )  const throw ()

Returns a 3-character string to indicate the local timezone.

const String Time::toString ( bool  includeDate,
bool  includeTime,
bool  includeSeconds = true,
bool  use24HourClock = false 
) const throw ()

Quick way of getting a string version of a date and time.

For a more powerful way of formatting the date and time, see the formatted() method.

Parameters:
includeDate whether to include the date in the string
includeTime whether to include the time in the string
includeSeconds if the time is being included, this provides an option not to include the seconds in it
use24HourClock if the time is being included, sets whether to use am/pm or 24 hour notation.
See also:
formatted
const String Time::formatted ( const String format  )  const throw ()

Converts this date/time to a string with a user-defined format.

This uses the C strftime() function to format this time as a string. To save you looking it up, these are the escape codes that strftime uses (other codes might work on some platforms and not others, but these are the common ones):

a is replaced by the locale's abbreviated weekday name. A is replaced by the locale's full weekday name. b is replaced by the locale's abbreviated month name. B is replaced by the locale's full month name. c is replaced by the locale's appropriate date and time representation. d is replaced by the day of the month as a decimal number [01,31]. H is replaced by the hour (24-hour clock) as a decimal number [00,23]. I is replaced by the hour (12-hour clock) as a decimal number [01,12]. j is replaced by the day of the year as a decimal number [001,366]. m is replaced by the month as a decimal number [01,12]. M is replaced by the minute as a decimal number [00,59]. p is replaced by the locale's equivalent of either a.m. or p.m. S is replaced by the second as a decimal number [00,61]. U is replaced by the week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. w is replaced by the weekday as a decimal number [0,6], with 0 representing Sunday. W is replaced by the week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. x is replaced by the locale's appropriate date representation. X is replaced by the locale's appropriate time representation. y is replaced by the year without century as a decimal number [00,99]. Y is replaced by the year with century as a decimal number. Z is replaced by the timezone name or abbreviation, or by no bytes if no timezone information exists. %% is replaced by %.

See also:
toString
const Time Time::operator+ ( const RelativeTime delta  )  const throw ()

Adds a RelativeTime to this time and returns the result.

const Time Time::operator- ( const RelativeTime delta  )  const throw ()

Subtracts a RelativeTime from this time and returns the result.

const RelativeTime Time::operator- ( const Time other  )  const throw ()

Returns the relative time difference between this time and another one.

bool Time::operator== ( const Time other  )  const throw ()

Compares two Time objects.

bool Time::operator!= ( const Time other  )  const throw ()

Compares two Time objects.

bool Time::operator< ( const Time other  )  const throw ()

Compares two Time objects.

References RelativeTime::milliseconds().

bool Time::operator<= ( const Time other  )  const throw ()

Compares two Time objects.

bool Time::operator> ( const Time other  )  const throw ()

Compares two Time objects.

bool Time::operator>= ( const Time other  )  const throw ()

Compares two Time objects.

bool Time::setSystemTimeToThisTime (  )  const throw ()

Tries to set the computer's clock.

Returns:
true if this succeeds, although depending on the system, the application might not have sufficient privileges to do this.
static const String Time::getWeekdayName ( int  dayNumber,
bool  threeLetterVersion 
) throw () [static]

Returns the name of a day of the week.

Parameters:
dayNumber the day, 0 to 6 (0 = sunday, 1 = monday, etc)
threeLetterVersion if true, it'll return a 3-letter abbreviation, e.g. "Tue"; if false, it'll return the full version, e.g. "Tuesday".
static const String Time::getMonthName ( int  monthNumber,
bool  threeLetterVersion 
) throw () [static]

Returns the name of one of the months.

Parameters:
monthNumber the month, 0 to 11
threeLetterVersion if true, it'll be a 3-letter abbreviation, e.g. "Jan"; if false it'll return the long form, e.g. "January"
static int64 Time::currentTimeMillis (  )  throw () [static]

Returns the current system time.

Returns the number of milliseconds since midnight jan 1st 1970.

Should be accurate to within a few millisecs, depending on platform, hardware, etc.

Referenced by InterProcessLock::Pimpl::Pimpl().

static uint32 Time::getMillisecondCounter (  )  throw () [static]

Returns the number of millisecs since system startup.

Should be accurate to within a few millisecs, depending on platform, hardware, etc.

See also:
getApproximateMillisecondCounter
static double Time::getMillisecondCounterHiRes (  )  throw () [static]

Returns the number of millisecs since system startup.

Same as getMillisecondCounter(), but returns a more accurate value, using the high-res timer.

See also:
getMillisecondCounter
static void Time::waitForMillisecondCounter ( uint32  targetTime  )  throw () [static]

Waits until the getMillisecondCounter() reaches a given value.

This will make the thread sleep as efficiently as it can while it's waiting.

static uint32 Time::getApproximateMillisecondCounter (  )  throw () [static]

Less-accurate but faster version of getMillisecondCounter().

This will return the last value that getMillisecondCounter() returned, so doesn't need to make a system call, but is less accurate - it shouldn't be more than 100ms away from the correct time, though, so is still accurate enough for a lot of purposes.

See also:
getMillisecondCounter
static int64 Time::getHighResolutionTicks (  )  throw () [static]

Returns the current high-resolution counter's tick-count.

This is a similar idea to getMillisecondCounter(), but with a higher resolution.

See also:
getHighResolutionTicksPerSecond, highResolutionTicksToSeconds, secondsToHighResolutionTicks
static int64 Time::getHighResolutionTicksPerSecond (  )  throw () [static]

Returns the resolution of the high-resolution counter in ticks per second.

See also:
getHighResolutionTicks, highResolutionTicksToSeconds, secondsToHighResolutionTicks
static double Time::highResolutionTicksToSeconds ( int64  ticks  )  throw () [static]

Converts a number of high-resolution ticks into seconds.

See also:
getHighResolutionTicks, getHighResolutionTicksPerSecond, secondsToHighResolutionTicks
static int64 Time::secondsToHighResolutionTicks ( double  seconds  )  throw () [static]

Converts a number seconds into high-resolution ticks.

See also:
getHighResolutionTicks, getHighResolutionTicksPerSecond, highResolutionTicksToSeconds

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Apr 26 11:42:19 2010 for JUCE by  doxygen 1.6.3