ã¯ããã«
ãä½æãã¦ããããã°ã©ã ã®ä¸ã§ãããæ¥ä»ã®ç¿æ¥ãåå¾ãããã¨ããç¶æ³ãæ³åãã¦ãã ãããä¸è¦åç´ãããªã¿ã¹ã¯ã§ãããèªåã§å®è£ ããã¨ãªãã¨ãããªãé¢åã ã¨ãããã¨ã¯å®¹æã«æ³åã§ãã¾ãããæ¥ãã27以ä¸ã®å ´åã¯åã«1ãå ããã°ããã®ã§ããï¼å®ã¯ããã¯ééãã§ãï¼ããæ¥ãã28以ä¸ã«ãªãã¨ãæ¥æ°ã¯æã«ãã£ã¦ç°ãªããããã¾ãããããä½æãªã®ãã調ã¹ãªããã°ãªãã¾ãããããã«ããã2æã ã£ããéå¹´ãªã®ãã©ããããã§ãã¯ããå¿ è¦ãããã¾ããããå¹´ãã4ã®åæ°ãªãéå¹´ãã¨ãããããªåç´ãªè©±ã§ã¯ãªããã¨ã¯ãåãã§ãããã
ã幸éãªãã¨ã«ãç¾å¨åºã使ããã¦ããããã°ã©ãã³ã°è¨èªã®å¤ãã¯ãæ¥ä»ãæå»ã®è¨ç®ã®ããã®ã©ã¤ãã©ãªãã¯ã©ã¹ãæã£ã¦ããã®ã§ãæ¦ã®è©³ç´°ãç¥ããªãã¦ããæ¥æãæ±ããã¨ãã§ããããã«ãªã£ã¦ãã¾ãã
ãPHPã«ãæ¥ä»ãæå»ãæ±ãããã®æ段ãç¨æããã¦ãã¦ãç°¡åã«ä½¿ããã¨ãã§ãã¾ããå°ã£ããã¨ã«ãè¤æ°ã®æ段ãããä¸ã«ããããã®ãããããä½ããã®åé¡ãæ±ãã¦ãã¾ãããã®è¨äºã§ã¯ãPHPã§æ¥æãæ±ãæ¨æºçãªæ¹æ³ã¨ããããã®ä½¿ç¨ä¸ã®æ³¨æç¹ãç´¹ä»ãã¾ããããã§ç´¹ä»ããã®ã¯æ¬¡ã®4ã¤ã®æ¹æ³ã§ãã
- ã¨ããã¯ã¿ã¤ã ã¹ã¿ã³ã
- PEAR Date
- DateTime
- ã¦ãªã¦ã¹æ¥
対象èªè
- PHPã§æ¥ä»ãæå»ãå¦çãããã¨ãããæ¹
- æ¦ã«ã¤ãã¦èå³ãããæ¹
å¿ è¦ãªç°å¢
ããã®è¨äºã®å 容ããã¹ã¦å®è¡ããããã«ã¯ãPHP 5.1以ä¸ãåä½ããç°å¢ãå¿ è¦ã§ããä¸é¨ã¯PHP 4ã§ãåä½ãã¾ãï¼çè ã®ç°å¢ã¯XAMPP for Windows 1.6.3aä¸ã®PHP 5.2.3ã§ãï¼ã
ã¨ããã¯ã¿ã¤ã ã¹ã¿ã³ã
date()
ã以ä¸ã®ããã«ãã¦ç¾å¨æå»ã表示ã§ãã¾ãã
echo date('r'); // Tue, 16 Oct 2007 16:50:06 +0900 // ï¼ç¾å¨æå»ãRFC 2822ãã©ã¼ãããã§è¡¨ç¤ºï¼
ããr
ãã¯date()
ã®ãã©ã¼ãããæåã§ãããã©ã¼ãããæåã¯ã»ãã«ãããããããã®ã§ãããã¥ã¢ã«ã®dete()ã®é
ãåç
§ãã¦ãã ããããã©ã¼ããããæå®ãããã¨ã§ãã¾ãã¾ãªå½¢å¼ã§è¡¨ç¤ºã§ããã®ã§ããã次ã®ãããªæ¨æºçãªãã©ã¼ãããããããããç¨æããã¦ãã¾ãã
echo date(DATE_ATOM); // 2007-10-16T16:50:06+09:00 echo date(DATE_COOKIE); // Tuesday, 16-Oct-07 16:50:06 JST echo date(DATE_ISO8601); // 2007-10-16T16:50:06+0900 echo date(DATE_RFC822); // Tue, 16 Oct 07 16:50:06 +0900 echo date(DATE_RFC850): // Tuesday, 16-Oct-07 16:50:06 JST echo date(DATE_RFC1036); // Tue, 16 Oct 07 16:50:06 +0900 echo date(DATE_RFC1123); // Tue, 16 Oct 2007 16:50:06 +0900 echo date(DATE_RFC2822); // Tue, 16 Oct 2007 16:50:06 +0900 echo date(DATE_RFC3339); // 2007-10-16T16:50:06+09:00 // ï¼DATE_ATOMã¨åãï¼ echo date(DATE_RSS); // Tue, 16 Oct 2007 16:50:06 +0900 echo date(DATE_W3C); // 2007-10-16T16:50:06+09:00
ã+900
ã+09:00
ãJST
ã¨ããã®ã¯ã¿ã¤ã ã¾ã¼ã³ã表ãã¦ãã¾ããããã©ã«ãã®ã¿ã¤ã ã¾ã¼ã³ã¯æ¬¡ã®ããã«åå¾ã»å¤æ´ã§ãã¾ãã
echo date_default_timezone_get(); // Asia/Tokyo date_default_timezone_set('GMT'); // ã¿ã¤ã ã¾ã¼ã³ãGMTã«å¤æ´ echo date('r'); // Tue, 16 Oct 2007 07:50:06 +0000
ã以ä¸ã§ã¯ç¹ã«æããªãéããã¿ã¤ã ã¾ã¼ã³ãGMTï¼ã°ãªããã¸æ¨æºæï¼ã¨ãã¾ããã¡ãªã¿ã«ãç¾å¨ã®å ¬å¼ãªæå»ã¯UTCï¼åå®ä¸çæï¼ã§ããUTCã¯ã»ã·ã¦ã 133ã9192631770åæ¯åããæéãåä½ã«ãããã®ã§ã天ä½è¦³æ¸¬ã«ãã£ã¦å®ã¾ãGMTã¨ã®å·®ãåããããã«ãé©å®éç§ãæ¿å ¥ããã¾ããå©ç¨å¯è½ãªã¿ã¤ã ã¾ã¼ã³ã¯List of Supported Timezonesã«åæããã¦ãã¾ãã
strftime()
ãstrftime()
ãdate()
ã¨ä¸¦ã¶æ¨æºçãªé¢æ°ã§ããstrftime()
ã使ã£ã¦ç¾å¨æå»ã表示ãã¦ã¿ã¾ãããã
//ç¾è¡ãã±ã¼ã«ã§ã®æ¨æºçãªå½¢å¼ echo strftime('%c'); // 10/16/07 07:50:06 //表示ãã©ã¼ããããæå® echo strftime('%A, %d %B'); // Tuesday, 16 October //date()ã§ãåããã¨ãã§ãã echo date('l, d F'); // Tuesday, 16 October
ã%A
ã%d
ã %B
ã¯strftime()
ã®ãã©ã¼ãããæååã§ãã詳細ã¯ããã¥ã¢ã«ã®strftime()ã®é
ãåç
§ãã¦ãã ããã
ãstrftime()
ã®åºåã¯ãã±ã¼ã«ã«ä¾åãã¾ããã¾ããç¾è¡ã®ãã±ã¼ã«ã確èªãã¾ãããã
echo setlocale(LC_ALL,0);
LC_COLLATE=C;LC_CTYPE=Japanese_Japan.932;LC_MONETARY=C; LC_NUMERIC=C;LC_TIME=C
ãæåã®åé¡ã»å¤ææ¥æã®è¨å®ã ããæ¥æ¬èªã»æ¥æ¬ã»CP932ï¼æåã³ã¼ããå¥åWindows-31Jï¼ã«ãªã£ã¦ãã¦ããã以å¤ã¯Cï¼Cè¨èªã®ããã®æä½éã®æ å ±ã®ã¿ï¼ã«ãªã£ã¦ãããã¨ãåããã¾ããæ¥æã®å½¢å¼ãæ¥æ¬èªã«ãã¾ããããå©ç¨å¯è½ãªãã±ã¼ã«ã«ã¤ãã¦ã¯ããã¥ã¢ã«ã®setlocale()ã®é ãåç §ãã¦ãã ããã
// setlocale(LC_ALL,'Japanese_Japan')ã§ããã setlocale(LC_TIME,'Japanese_Japan'); echo strftime('%c'); // 2007/10/16 7:50:06 echo iconv('CP932','UTF-8',strftime('%A, %d %B')); // ç«ææ¥, 16 10æ echo date('l, d F'); // Tuesday, 16 Octoberï¼dateã¯ãã±ã¼ã«ã«ãããªãï¼
ããJapanese_Japan
ãã®ãããªãã±ã¼ã«ãæå®ããæååã¯OSã«ãã£ã¦å¤ãããã¨ã«æ³¨æãã¦ãã ãããWindows以å¤ã®OSã§ã¯ãja_JP
ãã¨ãªãã¾ãï¼ãã®ç
©ããããã解æ¾ãããæ¹æ³ã¯å¥ã®æ©ä¼ã«ç´¹ä»ãã¾ãããï¼ã
ã以ä¸ã§ã¯ç¹ã«æããªãéãããã±ã¼ã«ã¯ãCãã¤ã¾ããsetlocale(LC_ALL,'C')
ããå®è¡ããã¦ããã¨ãã¾ãã