应该以{{1}}的形式向代表0000:00:0:00:00
的用户显示时间。我将需要一些方法来增加/减少/设置时间。
如何使用PHP YYYY:WW:D:HH:MM
实现此目标?即使我只有一个小时,也应该始终以这种格式显示它DateTime()
。
感谢您的帮助!
应该以{{1}}的形式向代表0000:00:0:00:00
的用户显示时间。我将需要一些方法来增加/减少/设置时间。
如何使用PHP YYYY:WW:D:HH:MM
实现此目标?即使我只有一个小时,也应该始终以这种格式显示它DateTime()
。
感谢您的帮助!
尝试一下:
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,这里是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");