Could somebody please take a look into my code:
$godzinaRozpoczecia = "10:35";
$dateStampGodzinaRozpoczecia = strtotime($godzinaRozpoczecia);
echo date("H:m", $dateStampGodzinaRozpoczecia);
RESULT: 10:08
var_dump($godzinaRozpoczecia);
RESULT: string(5) "10:35"
What is wrong? Why do I have minutes missing? In var_dump
everything seems to be fine. The same issue occurs when I retrieve the time from the database.
The date()
function specifies the following format for "H:m"
:
- H: 24-hour format of an hour with leading zeros
- m: Numeric representation of a month, with leading zeros
So you're actually showing the month here, you're looking for i
:
- i: Minutes with leading zeros
You may have been confused with the format used for the strtotime()
, DateTime
and date_create()
formats . They are different from the date()
formats (for some illogical reason).
Try this
date("H:i", $dateStampGodzinaRozpoczecia);
//m is for month.current month is August that is only it gives you 08 as aswer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.