¥È¥Ã¥×   ÊÔ½¸ Åà·ë º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS

PHP/Æü»þ

Last-modified: 2018-11-14 (¿å) 15:23:57 (2153d)
Top / PHP / Æü»þ

PHP

¥¿¥¤¥à¥¾¡¼¥óÀßÄê

date_default_timezone_set('Asia/Tokyo');

¥¿¥¤¥à¥¹¥¿¥ó¥×

¥µ¡¼¥Ð¾å¤Ç¤Î¡¢1970ǯ1·î1Æü00»þ00ʬ00Éà GMT ¤«¤é¤Î·Ð²áÉÿô

time

// ¸½ºß¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¼èÆÀ
$iTimeStamp = time();

mktime

// »ØÄêÆü»þ¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¼èÆÀ
$iTimeStamp = mktime([int »þ[, int ʬ[, int ÉÃ[, int ·î[, int Æü[, ǯ]]]]]]);

gmmktime

// GMT»ØÄêÆü»þ¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¼èÆÀ
$iTimeStamp = gmmktime([int »þ[, int ʬ[, int ÉÃ[, int ·î[, int Æü[, ǯ]]]]]]);

strtotime

// »ØÄêʸ»úÎó¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¼èÆÀ
$iTimeStamp = strtotime('2006-09-04 18:34:11')

filemtime

// ¥Õ¥¡¥¤¥ëºÇ½ª¹¹¿·Æü»þ¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¼èÆÀ
$iTimeStamp = filemtime('index.html')

getdate¤Ë¤è¤ëÆü»þ¾ðÊó¤Î¼èÆÀ

    /**
     * Æü»þʸ»úÎó¼èÆÀ
     * @param $iTimeStamp ¥¿¥¤¥à¥¹¥¿¥ó¥×
     * @return ¼¡¤Î¤è¤¦¤Êʸ»úÎó¤òÊÖ¤·¤Þ¤¹¡£2008ǯ2·î10Æü(Æü) ¸á¸å7»þ21ʬ26ÉÃ
     */
    function getDateString($iTimeStamp)
    {
        $arStrDayOfTheWeek = array("Æü", "·î", "²Ð", "¿å", "ÌÚ", "¶â", "ÅÚ");
        $arDateInfo = getdate($iTimeStamp);
        $strDayOfTherWeek = $arStrDayOfTheWeek[$arDateInfo['wday']];
        $strReturn = $arDateInfo['year']."ǯ".$arDateInfo['mon']."·î".$arDateInfo['mday']."Æü(".$strDayOfTherWeek.") ";
        if ($arDateInfo['hours'] >= 12) {
            $strReturn .= "¸á¸å";
        } else {
            $strReturn .= "¸áÁ°";
        }
        $strReturn .= ($arDateInfo['hours'] % 12)."»þ".$arDateInfo['minutes']."ʬ".$arDateInfo['seconds']."ÉÃ";
        return $strReturn;
    }
    print getDateString(time())."<br>\n";

date¤Ë¤è¤ëÆü»þʸ»úÎó¤Î¥Õ¥©¡¼¥Þ¥Ã¥È

$strDate = date(¥Õ¥©¡¼¥Þ¥Ã¥Èʸ»úÎó[, ¥¿¥¤¥à¥¹¥¿¥ó¥×]);
// ¸½ºß¤ÎÆü»þ¤òɽ¼¨
// 2006-09-14 (Thu) 12:20:45
print date("Y-m-d (D) H:i:s", time())
¥Õ¥©¡¼¥Þ¥Ã¥ÈÆâÍÆÎã
YÀ¾Îñǯ2011
yÀ¾Îñǯ²¼£²·å11
m·î¡§0¥Õ¥£¥ëɽµ­01¡Á12
n·î¡§¿ô»úɽµ­1¡Á12
F·î¡§±Ñ¸ìɽµ­January, ...
M·î¡§£³Ê¸»úɽµ­Jan, ...
jÆü¡§¿ô»úɽµ­1¡Á31
dÆü¡§0¥Õ¥£¥ëɽµ­01¡Á31
wÍËÆü¡§¿ô»úɽµ­0:ÆüÍËÆü, 1:·îÍËÆü, ...
lÍËÆü¡§±Ñ¸ìɽµ­Sunday, Monday, ...
DÍËÆü¡§£³Ê¸»úɽµ­Sun, Mon, ...
AAM¤Þ¤¿¤ÏPMAM, PM
g»þ´Ö¡§12»þ´Öɽµ­1¡Á12
G»þ´Ö¡§24»þ´Öɽµ­1¡Á24
h»þ´Ö¡§12»þ´Ö£°¥Õ¥£¥ëɽµ­01¡Á12
H»þ´Ö¡§24»þ´Ö£°¥Õ¥£¥ëɽµ­01¡Á24
iʬ00¡Á59
sÉÃ00¡Á59
u¥Þ¥¤¥¯¥íÉÃ(PHP 5.2.2¤«¤é)0¡Á999

checkdate¤Ë¤è¤ëÆüÉÕ¥Á¥§¥Ã¥¯

checkdate(·î, Æü, ǯ)¤Ç¡¢Â¸ºß¤¹¤ëÆüÉդΤȤ­TRUE¤¬ÊÖ¤ê¤Þ¤¹¡£
for ($i = 1; checkdate(2, $i, 2008); $i++) {
    print("$i ");
}

¥ê¥ó¥¯