Two functions, date() and gmdate(), format dates and times. Date() formats local times while gmdate() formats GMT times. Both accept a format string as the first parameter and an optional timestamp. If no timestamp is provided, the current time is used. Additionally, strftime() and gmstrftime() format dates according to the locale setting, with strftime() for local times and gmstrftime() for GMT. A table lists formatting modifiers that can be used within the format string, including modifiers for AM/PM, century, special characters, days, and months.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
18 views
Formatting Date and Time in PHP
Two functions, date() and gmdate(), format dates and times. Date() formats local times while gmdate() formats GMT times. Both accept a format string as the first parameter and an optional timestamp. If no timestamp is provided, the current time is used. Additionally, strftime() and gmstrftime() format dates according to the locale setting, with strftime() for local times and gmstrftime() for GMT. A table lists formatting modifiers that can be used within the format string, including modifiers for AM/PM, century, special characters, days, and months.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
9.4.
2 Formatting Date and Time
Making a GMT date with gmmktime() and then showing it in the current time zone with the date() function doesnt make much sense. Thus, we also have two functions for formatting date/time: date() to format a local date/time, and gmdate() to format a GMT date/time. Both functions accept exactly the same parameters. The first parameter is a format string (more about that in a bit), and the second is an optional timestamp. If the timestamp parameter is not included, the current time is used in formatting the output. gmdate() and date() always format the date in English, not in the current locale that is set on your system. Two functions are provided to format local time/date according to locale settings: strftime() for local time and gmstrftime() for GMT times. Table 9.6 describes formatting string characters for both functions. Note that the (gm)strftime() prefix to the formatting string options with a %. Table 9.6 Date Formatting Modifiers Description date / gmdate strftime / gmstrftime Remarks AM/PM A am/pm a %p Either am or pm for the English locale. Other locales might have their replacements (for example, nl_NL has an empty string here). Century, numeric two digits %C Returns the century number 20 for 2004, and so on. Character, literal % %% Use this to place a literal character % inside the formatting string. Character, newline %n Use this to place a newline character inside the formatting string. Character, tab %t Use this to place a tab character inside the formatting string. Day count in month t Number of days in the month defined by the timestamp. Day of month, leading spaces %e Current day in this month defined by the timestamp. A space is prepended when the day number is less than 10. Day of month, leading zeros d %D Current day in this month defined by the timestamp. A zero is prepended when the day number is less than 10. Day of month, without leading zeros j Current day in this month defined by the timestamp. Gutmans_ch09 Page 305 Thursday, September 23, 2004 2:47 PM