1 | function FormatDateTime ( const Formatting : string; DateTime : TDateTime ) : string; |
2 | function FormatDateTime ( const Formatting : string; DateTime : TDateTime; const FormatSettings : TFormatSettings ) : string; |
The Formatting string can comprise a mix of ordinary characters (that are passed unchanged to the result string), and data formatting characters. This formatting is best explained by the example code.
The following (non-Asian) formatting character strings can be used in the Formatting string:
y | = Year last 2 digits |
yy | = Year last 2 digits |
yyyy | = Year as 4 digits |
m | = Month number no-leading 0 |
mm | = Month number as 2 digits |
mmm | = Month using ShortDayNames (Jan) |
mmmm | = Month using LongDayNames (January) |
d | = Day number no-leading 0 |
dd | = Day number as 2 digits |
ddd | = Day using ShortDayNames (Sun) |
dddd | = Day using LongDayNames (Sunday) |
ddddd | = Day in ShortDateFormat |
dddddd | = Day in LongDateFormat |
c | = Use ShortDateFormat + LongTimeFormat |
h | = Hour number no-leading 0 |
hh | = Hour number as 2 digits |
n | = Minute number no-leading 0 |
nn | = Minute number as 2 digits |
s | = Second number no-leading 0 |
ss | = Second number as 2 digits |
z | = Milli-sec number no-leading 0s |
zzz | = Milli-sec number as 3 digits |
t | = Use ShortTimeFormat |
tt | = Use LongTimeFormat |
am/pm | = Use after h : gives 12 hours + am/pm |
a/p | = Use after h : gives 12 hours + a/p |
ampm | = As a/p but TimeAMString,TimePMString |
/ | = Substituted by DateSeparator value |
: | = Substituted by TimeSeparator value |
Important : if you want to see characters such as dd in the formatted output, placing them in " marks will stop them being interpreted as date or time elements.
In addition to this formatting, various of the above options are affected by the following variables, withe their default values :
DateSeparator | = / |
TimeSeparator | = : |
ShortDateFormat | = dd/mm/yyyy |
LongDateFormat | = dd mmm yyyy |
TimeAMString | = AM |
TimePMString | = PM |
ShortTimeFormat | = hh:mm |
LongTimeFormat | = hh:mm:ss |
ShortMonthNames | = Jan Feb ... |
LongMonthNames | = January, February ... |
ShortDayNames | = Sun, Mon ... |
LongDayNames | = Sunday, Monday ... |
TwoDigitYearCenturyWindow | = 50 |
Related commands
DateSeparator | The character used to separate display date fields |
DateTimeToStr | Converts TDateTime date and time values to a string |
DateTimeToString | Rich formatting of a TDateTime variable into a string |
LongDateFormat | Long version of the date to string format |
LongDayNames | An array of days of the week names, starting 1 = Sunday |
LongMonthNames | An array of days of the month names, starting 1 = January |
LongTimeFormat | Long version of the time to string format |
ShortDateFormat | Compact version of the date to string format |
ShortDayNames | An array of days of the week names, starting 1 = Sunday |
ShortMonthNames | An array of days of the month names, starting 1 = Jan |
ShortTimeFormat | Short version of the time to string format |
StrToDateTime | Converts a date+time string into a TDateTime value |
TimeAMString | Determines AM value in DateTimeToString procedure |
TimePMString | Determines PM value in DateTimeToString procedure |
TimeSeparator | The character used to separate display time fields |
TwoDigitYearCenturyWindow | Sets the century threshold for 2 digit year string conversions |
from http://www.delphibasics.co.uk/RTL.asp?Name=FormatDateTime