hor*_*gen 10 php weekday unix-timestamp
如何从PHP中的Unix时间戳获取日期(1-7)?我还需要日期(1-31)和月份(1-12).
mar*_*vin 43
您可以使用date()函数
$weekday = date('N', $timestamp); // 1-7
$month = date('m', $timestamp); // 1-12
$day = date('d', $timestamp); // 1-31
Run Code Online (Sandbox Code Playgroud)
例如
$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";
Run Code Online (Sandbox Code Playgroud)
小智 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42402 次 |
| 最近记录: |