DateTimeFormat Class Reference

A formatter for dates and times. More...

#include <DateTimeFormat.h++>

List of all members.

Classes

class  Token

Public Member Functions

 DateTimeFormat (String format="%t %T", String dateFormat="%t", String timeFormat="%T")
 Construct a new DateTimeFormat.
 ~DateTimeFormat () throw ()
 Destructor.
void setFormat (const String &format)
 Set the format for dates with times.
void setDateFormat (const String &dateFormat)
 Set the format for dates.
void setTimeFormat (const String &timeFormat)
 Set the format for times.
String format (const Date &value) const
 Format a Date.
size_t format (const Date &value, char *buf, size_t bufsz) const
 Format a DateTime.
String format (const Time &value) const
 Format a Time.
size_t format (const Time &value, char *buf, size_t bufsz) const
 Format a DateTime.
String format (const DateTime &value) const
 Format a DateTime.
size_t format (const DateTime &value, char *buf, size_t bufsz) const
 Format a DateTime.
void parse (Date &value, const String &text) const throw (ParseException)
 Parse a Date from a string.
void parse (Time &value, const String &text) const throw (ParseException)
 Parse a Time from a string.
void parse (DateTime &value, const String &text) const throw (ParseException)
 Parse a DateTime from a string.

Detailed Description

A formatter for dates and times.

Available format directives are enumerated below. Unrecognized directives are ignored, and all other text is treated literally.

DirectiveMeaningRange
%HHour of 24-hour clock0 - 23
%0HHour of 24-hour clock (padded with leading zeroes)00 - 23
%_HHour of 24-hour clock (padded with leading spaces) 0 - 23
%hHour of 12-hour clock1 - 12
%0hHour of 12-hour clock (padded with leading zeroes)01 - 12
%_hHour of 12-hour clock (padded with leading spaces) 1 - 12
%MMinutes (unpadded)0 - 59
%0MMinutes (padded with leading zeroes)00 - 59
%_MMinutes (padded with leading spaces) 0 - 59
%SSeconds (unpadded)0 - 60
%0SSeconds (padded with leading zeroes)00 - 60
%_SSeconds (padded with leading spaces) 0 - 60
%sMilliseconds (unpadded)0 - 999
%0sMilliseconds (padded with leading zeroes)000 - 999
%_sMilliseconds (padded with leading spaces)

  0 - 999

%dDay of month1 - 31
%0dDay of month (padded with leading zeroes)01 - 31
%_dDay of month (padded with leading spaces)

 1 - 31

%DDay of year1 - 366
%0DDay of year (padded with leading zeroes)001 - 366
%_DDay of year (padded with leading spaces)

  1 - 366

%mMonth number (1 = January)1 - 12
%0mMonth number (1 = January) (padded with leading zeroes)01 - 12
%_mMonth number (1 = January) (padded with leading spaces) 1 - 12
%$mAbbreviated month name
%$$mFull month name
%wWeekday number (0 = Sunday)0 - 6
%$wAbbreviated weekday name
%$$w

Full weekday name

%WWeek number (ISO standard)0 - 52
%0WWeek number (ISO standard) (padded with leading zeroes)00 - 52
%_wWeek number (ISO standard) (padded with leading spaces)

 0 - 52

%y2-digit year 0 - 99
%0y2-digit year (padded with leading zeroes)00 - 99
%_y2-digit year (padded with leading spaces) 0 - 99
%Y4-digit year 0 - 9999
%0Y4-digit year (padded with leading zeroes)0000 - 9999
%_Y4-digit year (padded with leading spaces)

   0 - 9999

%PMeridiem (uppercase) (local form of "AM" or "PM")
%pMeridiem (lowercase) (local form of "am" or "pm")
%tDate
%TTime
%ZTime zone name
%%Percent sign
Author:
Mark Lindner

Constructor & Destructor Documentation

DateTimeFormat ( String  format = "%t %T",
String  dateFormat = "%t",
String  timeFormat = "%T" 
)

Construct a new DateTimeFormat.

Parameters:
format The format for dates with times.
dateFormat The format for dates.
timeFormat The format for times.
~DateTimeFormat (  )  throw ()

Destructor.


Member Function Documentation

size_t format ( const DateTime value,
char *  buf,
size_t  bufsz 
) const

Format a DateTime.

Parameters:
value The DateTime to format.
buf A raw character buffer to write the formatted value to.
bufsz The size of the character buffer.
Returns:
The number of characters written to the buffer.
String format ( const DateTime value  )  const

Format a DateTime.

Parameters:
value The DateTime to format.
Returns:
The formatted string representation of the date & time.
size_t format ( const Time value,
char *  buf,
size_t  bufsz 
) const

Format a DateTime.

Parameters:
value The Time to format.
buf A raw character buffer to write the formatted value to.
bufsz The size of the character buffer.
Returns:
The number of characters written to the buffer.
String format ( const Time value  )  const

Format a Time.

Parameters:
value The Time to format.
Returns:
The formatted string representation of the time.
size_t format ( const Date value,
char *  buf,
size_t  bufsz 
) const

Format a DateTime.

Parameters:
value The Date to format.
buf A raw character buffer to write the formatted value to.
bufsz The size of the character buffer.
Returns:
The number of characters written to the buffer.
String format ( const Date value  )  const

Format a Date.

Parameters:
value The Date to format.
Returns:
The formatted string representation of the date.
void parse ( DateTime value,
const String text 
) const throw (ParseException)

Parse a DateTime from a string.

Parameters:
value The value to parse into.
text The string to parse.
Exceptions:
ParseException If a parse error occurs.
void parse ( Time value,
const String text 
) const throw (ParseException)

Parse a Time from a string.

Parameters:
value The value to parse into.
text The string to parse.
Exceptions:
ParseException If a parse error occurs.
void parse ( Date value,
const String text 
) const throw (ParseException)

Parse a Date from a string.

Parameters:
value The value to parse into.
text The string to parse.
Exceptions:
ParseException If a parse error occurs.
void setDateFormat ( const String dateFormat  )  [inline]

Set the format for dates.

void setFormat ( const String format  )  [inline]

Set the format for dates with times.

void setTimeFormat ( const String timeFormat  )  [inline]

Set the format for times.


The documentation for this class was generated from the following files:
Generated on Sat Nov 26 16:49:09 2011 for libcommonc++ by  doxygen 1.6.3