Formatting Date and Time

来自WordPress中文文档
Zhuozuran讨论 | 贡献2009年3月14日 (六) 09:23的版本 (1个修订)
跳转至: 导航搜索

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. Therefore, 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.

p class=postmetadata altsmallThis entry was posted on ?php the_time('l, F jS, Y') ? and is filed under ?php the_category(', ') ?./small/p

p class=postmetadata altsmallThis entry was posted on Friday, September 24, 2004 and is filed under uWordPress/u and uWordPress Tips/u./small/p

Localization

You might want to display the date in your own language:

code

?php
setlocale(LC_ALL, 'nl_NL.ISO-8859-15@euro');
echo strftime('%A %d %B, %Y',strtotime(get_the_time('m/d/Y')));
?

/code

For this to work, your server has to be configured properly. The locale you are using (nl_NL.ISO-8859-15@euro) must be available.

Event, Calendar, and Time Plugins