如何从PHP中的Unix时间戳获取日期(1-7)?我还需要日期(1-31)和月份(1-12)。
答案 0 :(得分:42)
您可以使用date()功能
$weekday = date('N', $timestamp); // 1-7
$month = date('m', $timestamp); // 1-12
$day = date('d', $timestamp); // 1-31
答案 1 :(得分:7)
请参阅http://docs.php.net/getdate
e.g。
$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";
答案 2 :(得分:6)
这是你所追求的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
答案 3 :(得分:2)
print "Week".date('N')."\n";
print "day of month " .date('d')."\n";
print "month ".date('m')."\n";
答案 4 :(得分:1)