【发布时间】:2011-01-29 08:28:33
【问题描述】:
如何从 PHP 中的 Unix 时间戳获取日期 (1-7)?我还需要日期 (1-31) 和月份 (1-12)。
【问题讨论】:
标签: php unix-timestamp weekday
如何从 PHP 中的 Unix 时间戳获取日期 (1-7)?我还需要日期 (1-31) 和月份 (1-12)。
【问题讨论】:
标签: php unix-timestamp weekday
你可以使用date()函数
$weekday = date('N', $timestamp); // 1-7
$month = date('m', $timestamp); // 1-12
$day = date('d', $timestamp); // 1-31
【讨论】:
例如
$ts = time(); // could be any timestamp
$d=getdate($ts);
echo 'day of the week: ', $d['wday'], "\n";
echo 'day of the month: ', $d['mday'], "\n";
echo 'month: ', $d['mon'], "\n";
【讨论】:
这是您所追求的 date() 函数。
您可以从 PHP 手册中获得更多详细信息,但简而言之,这里有您需要的功能。
date('N', $timestamp);
//numeric representation of the day of the week
date('j', $timestamp);
//Day of the month without leading zeros
date('n', $timestamp);
//Numeric representation of a month, without leading zeros
【讨论】:
print "Week".date('N')."\n";
print "day of month " .date('d')."\n";
print "month ".date('m')."\n";
【讨论】: