如何以这种格式显示时间?

问题描述 投票:-1回答:2

时间应该像0000:00:0:00:00一样显示给代表YYYY:WW:D:HH:MM的用户。我需要增加/减少/设置时间的方法。

如何使用PHP DateTime()实现这一目标?即使我只有一个小时,也应该始终以这种格式显示它0000:00:0:01:00

感谢您的帮助!

php date datetime time week-number
2个回答
0
投票
echo date('Y:m:j:h:i');

https://www.php.net/manual/en/function.date.php日期的第二个参数是时间戳记


0
投票
Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003 W ISO-8601 week number of year, weeks starting on Monday Example: 42 (the 42nd week in the year) m Numeric representation of a month, with leading zeros 01 through 12 j Day of the month without leading zeros 1 to 31 H 24-hour format of an hour with leading zeros 00 through 23 i Minutes with leading zeros 00 to 59

关于您的问题,请参考How to create datetime from week number。这是Demo
$str = '2019-45-09 12:07'; $arr = explode(" ",$str); $date_arr = explode("-",$arr[0]); $time_arr = explode(":",$arr[1]); $date = new DateTime(); $date->setISODate($date_arr[0],$date_arr[1],$date_arr[2])->setTime($time_arr[0],$time_arr[1]); echo $date->format("Y-W-d H:i:s") . PHP_EOL; $date->add(new DateInterval("P1D")); echo $date->format("Y-W-d H:i:s");
© www.soinside.com 2019 - 2024. All rights reserved.