Skip to main content

TimeFormat

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

AttributeTypeDescription
datadatetime.date, datetime.time, or datetime.datetimeThe date, time, or datetime object to be formatted by the class methods.
timezonedatetime.tzinfo = NoneThe timezone information used for formatting, which is only populated for non-ambiguous datetime objects.

Constructor

Signature

def TimeFormat(
obj: object
)

Parameters

NameTypeDescription
objobjectThe date, time, or datetime object to be formatted.

Signature

def TimeFormat(
obj: datetime.date | datetime.time | datetime.datetime
)

Parameters

NameTypeDescription
obj`datetime.datedatetime.time

Methods


a()

@classmethod
def a() - > string

'a.m.' or 'p.m.'

Returns

TypeDescription
stringThe lowercase localized meridiem indicator.

A()

@classmethod
def A() - > string

'AM' or 'PM'

Returns

TypeDescription
stringThe uppercase localized meridiem indicator.

e()

@classmethod
def e() - > string

Timezone name. If timezone information is not available, return an empty string.

Returns

TypeDescription
stringThe 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

TypeDescription
stringThe formatted time string with optional minutes.

g()

@classmethod
def g() - > integer

Hour, 12-hour format without leading zeros; i.e. '1' to '12'

Returns

TypeDescription
integerThe 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

TypeDescription
integerThe hour of the day in 24-hour format.

h()

@classmethod
def h() - > string

Hour, 12-hour format; i.e. '01' to '12'

Returns

TypeDescription
stringThe zero-padded hour in 12-hour format.

H()

@classmethod
def H() - > string

Hour, 24-hour format; i.e. '00' to '23'

Returns

TypeDescription
stringThe zero-padded hour in 24-hour format.

i()

@classmethod
def i() - > string

Minutes; i.e. '00' to '59'

Returns

TypeDescription
stringThe 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

TypeDescription
stringThe 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

TypeDescription
stringA human-friendly formatted time string.

s()

@classmethod
def s() - > string

Seconds; i.e. '00' to '59'

Returns

TypeDescription
stringThe 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

TypeDescription
stringThe timezone abbreviation or an empty string.

u()

@classmethod
def u() - > string

Microseconds; i.e. '000000' to '999999'

Returns

TypeDescription
stringThe 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

TypeDescription
`integerstring`