php gmt 0800,PHP产生RSS pubDate所需日期时间格式

RSS / ATOM 的格式要产生都很简单, 麻烦的是日期格式的产生(RSS => pubDate, ATOM => created).

发现 PHP Date 有提供这些需要的相关全域变量可以使用:(PHP 5.1.1 以后开始支援这些全域变量)

echo DATE_RSS; // D, d M Y H:i:s O

echo DATE_ATOM; // Y-m-d\TH:i:sP

echo date(DATE_RSS); // Wed, 23 Apr 2008 19:27:19 +0800

echo date(DATE_ATOM); // 2008-04-23T19:27:38+08:00

如果是 MySQL timestamp/datetime format 直接拉出来的资料, 就可以直接使用:

date(DATE_RSS, strtotime($MYSQL_DATETIME_DATA));

目前支持的日期全域变量有以下:

DATE_ATOM: Atom  Atom (example: 2005-08-15T15:52:01+00:00)

DATE_COOKIE: HTTP Cookies (example: Monday, 15-Aug-05 15:52:01 UTC)

DATE_ISO8601: ISO-8601 (example: 2005-08-15T15:52:01+0000)

DATE_RFC822: RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000)

DATE_RFC850: RFC 850 (example: Monday, 15-Aug-05 15:52:01 UTC)

DATE_RFC1036: RFC 1036 (example: Mon, 15 Aug 05 15:52:01 +0000)

DATE_RFC1123: RFC 1123 (example: Mon, 15 Aug 2005 15:52:01 +0000)

DATE_RFC2822: RFC 2822 (Mon, 15 Aug 2005 15:52:01 +0000)

DATE_RFC3339: Same as DATE_ATOM

DATE_RSS: RSS (Mon, 15 Aug 2005 15:52:01 +0000)

DATE_W3C: World Wide Web Consortium (example: 2005-08-15T15:52:01+00:00)

PHP 预定义的日期格式

自 PHP 5.1.1 起定义有以下常量来提供标准日期表达方法,可以用于日期格式函数

echo DATE_RSS; // D, d M Y H:i:s O

echo DATE_ATOM; // Y-m-d\TH:i:sP

echo date(DATE_RSS); // Wed, 23 Apr 2008 19:27:19 +0800

echo date(DATE_ATOM); // 2008-04-23T19:27:38+08:00

虽然格式简单, 但用PHP内的预定义格式岂不更加方便.

目前PHP所有支持的日期格式:

DATE_ATOM: Atom  Atom (example: 2005-08-15T15:52:01+00:00)

DATE_COOKIE: HTTP Cookies (example: Monday, 15-Aug-05 15:52:01 UTC)

DATE_ISO8601: ISO-8601 (example: 2005-08-15T15:52:01+0000)

DATE_RFC822: RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000)

DATE_RFC850: RFC 850 (example: Monday, 15-Aug-05 15:52:01 UTC)

DATE_RFC1036: RFC 1036 (example: Mon, 15 Aug 05 15:52:01 +0000)

DATE_RFC1123: RFC 1123 (example: Mon, 15 Aug 2005 15:52:01 +0000)

DATE_RFC2822: RFC 2822 (Mon, 15 Aug 2005 15:52:01 +0000)

DATE_RFC3339: Same as DATE_ATOM

DATE_RSS: RSS (Mon, 15 Aug 2005 15:52:01 +0000)

DATE_W3C: World Wide Web Consortium (example: 2005-08-15T15:52:01+00:00)

PHP Date / Time Functions

PHP: indicates the earliest version of PHP that supports the function.

Function

Description

PHP

checkdate()

Validates a Gregorian date

3

date_default_timezone_get()

Returns the default time zone

5

date_default_timezone_set()

Sets the default time zone

5

date_sunrise()

Returns the time of sunrise for a given day / location

5

date_sunset()

Returns the time of sunset for a given day / location

5

date()

Formats a local time/date

3

getdate()

Returns an array that contains date and time information for a Unix timestamp

3

gettimeofday()

Returns an array that contains current time information

3

gmdate()

Formats a GMT/UTC date/time

3

gmmktime()

Returns the Unix timestamp for a GMT date

3

gmstrftime()

Formats a GMT/UTC time/date according to locale settings

3

idate()

Formats a local time/date as integer

5

localtime()

Returns an array that contains the time components of a Unix timestamp

4

microtime()

Returns the microseconds for the current time

3

mktime()

Returns the Unix timestamp for a date

3

strftime()

Formats a local time/date according to locale settings

3

strptime()

Parses a time/date generated with strftime()

5

strtotime()

Parses an English textual date or time into a Unix timestamp

3

time()

Returns the current time as a Unix timestamp

3

PHP Date / Time Constants

PHP: indicates the earliest version of PHP that supports the constant.

Constant

Description

PHP

DATE_ATOM

Atom (example: 2005-08-15T16:13:03+0000)

DATE_COOKIE

HTTP Cookies (example: Sun, 14 Aug 2005 16:13:03 UTC)

DATE_ISO8601

ISO-8601 (example: 2005-08-14T16:13:03+0000)

DATE_RFC822

RFC 822 (example: Sun, 14 Aug 2005 16:13:03 UTC)

DATE_RFC850

RFC 850 (example: Sunday, 14-Aug-05 16:13:03 UTC)

DATE_RFC1036

RFC 1036 (example: Sunday, 14-Aug-05 16:13:03 UTC)

DATE_RFC1123

RFC 1123 (example: Sun, 14 Aug 2005 16:13:03 UTC)

DATE_RFC2822

RFC 2822 (Sun, 14 Aug 2005 16:13:03 +0000)

DATE_RSS

RSS (Sun, 14 Aug 2005 16:13:03 UTC)

DATE_W3C

World Wide Web Consortium (example: 2005-08-14T16:13:03+0000)

其它相关网页:

虽然格式很简单, 但是有更多已经写好的 Library 可以直接使用, 会省掉不少时间, 详可参考:(不过下述我没用过就是了.. Orz.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值