WordPress 中文文档

Formatting Date and Time

出自WordPress Chinese 中文文档

跳转到: 导航, 搜索

wordpress.org.cn

Customizing the Time and Date

Certain WordPress tag functions are used to display or return date and time information; the_date() and the_time() are examples of this. Some of these functions accept a parameter called a format string that allows you to determine how the date is going to be displayed. The format string is a template in which various parts of the date are combined (using format characters) to generate a date in the format specified.

For example, the format string:

l, F j, Y

creates a date that look like this:

Friday, September 24, 2004

Here is what each format character in the string above represents:

  • codel/code = Full name for day of the week (lower-case L).
  • codeF/code = Full name for the month.
  • codej/code = The day of the month.
  • codeS/code = The English suffix for the day of the month (e.g st, nd or th in the 1st, 2nd or 15th.)
  • codeY/code = The year in 4 digits. (lower-case y gives the year's last 2 digits)
(Commas are read literally.)

WordPress is written in the programming language PHP. The date formatting functions in WordPress use PHP's built-in date formatting functions. You can use the table of date format characters on the PHP website as a reference for building date format strings for use in WordPress. Here is a table of some of the more useful items found there:

table width=80% style=margin-left:10%; margin-bottom:5%; class=widefat tr th style=background:#eee colspan=3Day of Month/th /tr trtdd/td tdNumeric, with leading zeros/td td01ndash;31/td /tr trtdj/td tdNumeric, without leading zeros/td td1ndash;31/td/tr trtdS/td tdEnglish ordinal suffix, use after j/td tdst, nd, rd or th/td /tr tr th style=background:#eee colspan=3Weekday/th /tr trtdl/td tdFull name nbsp;(lowercase 'L')/td tdSunday ndash; Saturday/td/tr trtdD/td tdThree letter name/td tdMon ndash; Sun/td/tr tr th style=background:#eee colspan=3Month/th /tr trtdm/td tdNumeric, with leading zeros/td td01ndash;12/td/tr trtdn/td tdNumeric, without leading zeros/td td1ndash;12/td/tr trtdF/td tdTextual full/td tdJanuary ndash; December/td/tr trtdM/td tdTextual three letters/td tdJan - Dec/td/tr tr th style=background:#eee colspan=3Year/th /tr tdY/td tdNumeric, 4 digits/td tdEg., 1999, 2003/td /tr trtdy/td tdNumeric, 2 digits/td tdEg., 99, 03/td /tr tr th style=background:#eee colspan=3Time/th /tr tr tda/td tdLowercase/td tdam, pm/td /tr tr tdA/td tdUppercase/td tdAM, PM/td/tr tr tdg/td tdHour, 12-hour, without leading zeros/td td1ndash;12/td /tr tr tdh/td tdHour, 12-hour, with leading zeros/td td01ndash;12/td /tr trtdG/td tdHour, 24-hour, without leading zeros/td td0-23/td/tr trtdH/td tdHour, 24-hour, with leading zeros/td td00-23/td/tr trtdi/td tdMinutes, with leading zeros/td td00-59/td/tr trtds/td tdSeconds, with leading zeros/td td00-59/td/tr trtdT/td tdTimezone abbreviation/td tdEg., EST, MDT .../td/tr tr th style=background:#eee colspan=3Full Date/Time/th /tr tr tdc/td tdISO 8601/td td2004-02-12T15:19:21+00:00/td /tr tr tdr/td tdRFC 2822/td tdThu, 21 Dec 2000 16:01:07 +0200/td /tr /table

This entry was posted on ?php the_time('l, F jS, Y') ? and is filed under ?php the_category(', ') ?.
This entry was posted on Friday, September 24th, 2004 and is filed under uWordPress/u and uWordPress Tips/u.

Localization

To localize dates, use the date_i18n() function.

wordpress