2w2d2h
。386
。2w=2*24*7
2d-2*24
2h=2
386
。386
时应显示2w2d2h
。请帮帮我
直到现在我已经在转换后插入了值。
preg_match_all('#(\d[wW]+|\d[dD]+|\d[hH]+|\s+)#i', $category, $matches);
$hours = 0;
$days = 0;
$hoursss = 0;
foreach ($matches[0] AS $match) {
switch(true) {
case preg_match('/\d[hH]+|\s+/', $match):
$hours += (int)$match;
break;
case preg_match('/\d[dD]+|\s+/', $match):
$days += (int)$match * 24;
break;
case preg_match('/\d[wW]+|s+/', $match):
$hoursss += (int)$match * 24 * 7;
break;
}
$case = $hours + $hoursss + $days;
}
答案 0 :(得分:2)
以下代码会将小时数转换为您需要的表达式:
$hours = 386;
$weeks = floor($hours / (24*7));
$hours -= $weeks * 24 * 7;
$days = floor($hours / 24);
$hours -= $days * 24;
printf("%dw%dd%dh", $weeks, $days, $hours);