/* * Return relative date format in Japanese, eg: 5時前 * max param indicates when to return absolute datetime * Default is 30 days */ function ja_relative_time($stamp, $max = 2592000) { $interval = date_create('now')->diff(new DateTime($stamp)); if ($interval->s >= $max) { return $stamp; } $suffix = ( $interval->invert ? '前' : '' ); if ( $v = $interval->y >= 1) return $interval->y . '年'. $suffix; if ( $v = $interval->m >= 1) return $interval->m . '月'. $suffix; if ( $v = $interval->d >= 1) return $interval->d . '日'. $suffix; if ( $v = $interval->h >= 1) return $interval->h . '時'. $suffix; if ( $v = $interval->i >= 1) return $interval->i . '分'. $suffix; return $interval->s . '秒'. $suffix; }
Jul 8, 2014
Relative date format in Japanese
Subscribe to:
Posts (Atom)