成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

PHP產生RSS pubDate所需日期時間格式

2011-11-29 10:57:47來源:作者:

RSS / ATOM 的格式要產生都很簡單, 麻煩的是日期格式的產生(RSS => pubDate, ATOM => created).

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.)

RSS Parser 可以考慮用下述的
關鍵詞:PHPRSS日期
主站蜘蛛池模板: 静海县| 公主岭市| 朝阳县| 梅州市| 开封市| 石阡县| 宜丰县| 祁连县| 彭阳县| 馆陶县| 临猗县| 桐梓县| 万全县| 怀安县| 高尔夫| 安仁县| 乳源| 天镇县| 三原县| 阳高县| 吴桥县| 舟山市| 奉节县| 延安市| 苏尼特右旗| 当涂县| 玉龙| 麦盖提县| 洪雅县| 民丰县| 年辖:市辖区| 达拉特旗| 柳江县| 阳泉市| 虹口区| 郴州市| 乳山市| 肥乡县| 准格尔旗| 左云县| 运城市|