php mktime AMPM value wrong
I'm trying to get the next minute value in php by doing the following.
$one_minute_later = mktime(date("g"), date("i")+1, date("s"), date("n"), date("j"), date("Y"));
$send_month = date("n", $one_minute_l开发者_高级运维ater); // Numeric representation of a month, without leading zeros
$send_day = date("j", $one_minute_later); // Day of the month without leading zeros
$send_year = date("Y", $one_minute_later);
$send_hour = date("g", $one_minute_later); // 12-hour format of an hour without leading zeros
$send_minute = date("i", $one_minute_later); // Minutes with leading zeros 00 to 59
$send_ampm = date("A", $one_minute_later);
However, doing so ALWAYS returns the value AM for AMPM. Any idea why? For instance, when I run this code at 6:00 PM, one minute later should return 6:01 PM. However, it's returning 6:01 AM.
Because mktime
works with 24 hours. Maybe you have noticed that it doesn't take an AM/PM parameter? That's because the hour parameter represents 24 hour time, not 12. Use date('H')
instead of date('g')
.
Or, simply use time() + 60
for this whole operation.
精彩评论