This class provides a set of methods for formatting time and datetime objects into various string representations. It supports a wide range of formats including 12-hour and 24-hour clocks, meridiem indicators, and detailed timezone information. The class automatically handles timezone detection for datetime objects and includes proprietary extensions for human-friendly time strings like 'midnight' or 'noon'.
Attributes
| Attribute | Type | Description |
|---|
| data | datetime.date, datetime.time, or datetime.datetime | The date, time, or datetime object to be formatted by the class methods. |
| timezone | datetime.tzinfo = None | The timezone information used for formatting, which is only populated for non-ambiguous datetime objects. |
Constructor
Signature
def TimeFormat(
obj: object
)
Parameters
| Name | Type | Description |
|---|
| obj | object | The date, time, or datetime object to be formatted. |
Signature
def TimeFormat(
obj: datetime.date | datetime.time | datetime.datetime
)
Parameters
| Name | Type | Description |
|---|
| obj | `datetime.date | datetime.time |
Methods
a()
@classmethod
def a() - > string
'a.m.' or 'p.m.'
Returns
| Type | Description |
|---|
string | The lowercase localized meridiem indicator. |
A()
@classmethod
def A() - > string
'AM' or 'PM'
Returns
| Type | Description |
|---|
string | The uppercase localized meridiem indicator. |
e()
@classmethod
def e() - > string
Timezone name. If timezone information is not available, return an empty string.
Returns
| Type | Description |
|---|
string | The name of the timezone or an empty string if unavailable. |
f()
@classmethod
def f() - > string
Time, in 12-hour hours and minutes, with minutes left off if they're zero. Examples: '1', '1:30', '2:05', '2' Proprietary extension.
Returns
| Type | Description |
|---|
string | The formatted time string with optional minutes. |
g()
@classmethod
def g() - > integer
Hour, 12-hour format without leading zeros; i.e. '1' to '12'
Returns
| Type | Description |
|---|
integer | The hour of the day in 12-hour format. |
G()
@classmethod
def G() - > integer
Hour, 24-hour format without leading zeros; i.e. '0' to '23'
Returns
| Type | Description |
|---|
integer | The hour of the day in 24-hour format. |
h()
@classmethod
def h() - > string
Hour, 12-hour format; i.e. '01' to '12'
Returns
| Type | Description |
|---|
string | The zero-padded hour in 12-hour format. |
H()
@classmethod
def H() - > string
Hour, 24-hour format; i.e. '00' to '23'
Returns
| Type | Description |
|---|
string | The zero-padded hour in 24-hour format. |
i()
@classmethod
def i() - > string
Minutes; i.e. '00' to '59'
Returns
| Type | Description |
|---|
string | The zero-padded minutes. |
O()
@classmethod
def O() - > string
Difference to Greenwich time in hours; e.g. '+0200', '-0430'. If timezone information is not available, return an empty string.
Returns
| Type | Description |
|---|
string | The UTC offset in hours and minutes or an empty string. |
P()
@classmethod
def P() - > string
Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off if they're zero and the strings 'midnight' and 'noon' if appropriate. Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.' Proprietary extension.
Returns
| Type | Description |
|---|
string | A human-friendly formatted time string. |
s()
@classmethod
def s() - > string
Seconds; i.e. '00' to '59'
Returns
| Type | Description |
|---|
string | The zero-padded seconds. |
T()
@classmethod
def T() - > string
Time zone of this machine; e.g. 'EST' or 'MDT'. If timezone information is not available, return an empty string.
Returns
| Type | Description |
|---|
string | The timezone abbreviation or an empty string. |
u()
@classmethod
def u() - > string
Microseconds; i.e. '000000' to '999999'
Returns
| Type | Description |
|---|
string | The zero-padded microseconds. |
Z()
@classmethod
def Z() - > integer | string
Time zone offset in seconds (i.e. '-43200' to '43200'). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. If timezone information is not available, return an empty string.
Returns
| Type | Description |
|---|
| `integer | string` |