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

How to display the time in this format?

时间应该像这样 0000:00:0:00:00 显示给代表 YYYY:WW:D:HH:MM 的用户。我将需要 add/reduce/set 时间的方法。

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

感谢任何帮助!

试试这个:

echo date('Y:m:j:h:i');

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

echo date('Y:W:j:H:i'); PHP Manual date

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 Here is the 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");