Created
October 3, 2016 05:29
-
-
Save eru/a29afa5aebd5f3a620266ab5c04ba57f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Short description for relative_time.php | |
* | |
* @package relative_time | |
* @author Kazuki Hashimoto <eru.tndl@gmail.com> | |
* @version 0.1 | |
* @copyright (C) 2016 Kazuki Hashimoto <eru.tndl@gmail.com> | |
* @license MIT | |
*/ | |
$now = time(); | |
$youtube_timestamp = 1475471853; | |
$youtube_timestamp -= 86400 * 31; | |
$diff = $now - $youtube_timestamp; | |
// 6days = 518400sec | |
if ($diff <= 518400) { | |
$time_text = floor($diff / 86400) . '日前'; | |
} | |
// 13days = 1123200sec | |
elseif ($diff <= 1123200) { | |
$time_text = '1週前'; | |
} | |
// 20days = 1728000sec | |
elseif ($diff <= 1728000) { | |
$time_text = '2週前'; | |
} | |
// 27days = 2332800sec | |
elseif ($diff <= 2332800) { | |
$time_text = '3週前'; | |
} | |
// 30days = 2592000sec | |
elseif ($diff <= 2592000) { | |
$time_text = '1ヶ月前'; | |
} | |
else { | |
$time_text = date('m月d日', $youtube_timestamp); | |
} | |
echo $time_text; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment