PHP를 사용한 ISO8601duration 일본어
4566 단어 PHP
PT1H1M1S
인 두아르션으로 답장할 때 일본어화된 호각반을 원해서 써봤어요.ISO8601 duration specification에 관해서는 P2Y3DT6H8M!?이 암호를 해석하기 위한 ISO8601 duration specification이란가 상세하므로 참조
참조: PHP: DateInterval::format - Manual
class Iso8601Formatter
{
public $val;
public function __construct($duration){
$this->val = $duration;
}
function toJp()
{
$interval = new \DateInterval($this->val);
$fmt = "";
if($interval->h > 0) {
$fmt.=('%h時間');
}
if($interval->i > 0){
$fmt.=('%i分');
}
if($interval->s > 0){
$fmt.=('%s秒');
}
return $interval->format($fmt);
}
}
echo join(PHP_EOL,
[
(new Iso8601Formatter('PT1H1M1S'))->toJp(),
(new Iso8601Formatter('PT14M10S'))->toJp(),
(new Iso8601Formatter('PT2H9M'))->toJp(),
(new Iso8601Formatter('PT2H59S'))->toJp()
]);
실행 결과1時間1分1秒
14分10秒
2時間9分
2時間59秒
Reference
이 문제에 관하여(PHP를 사용한 ISO8601duration 일본어), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hirocueki2/items/89b590518b171736777e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)