Created
October 23, 2014 19:33
-
-
Save gklka/a401f6a8a046695730c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function get_the_relative_time($time = null){ | |
if(is_null($time)) $time = get_the_time("U"); | |
// $time_diff = date("U") - $time; // difference in second | |
/* | |
$second = 1; | |
$minute = 60; | |
$hour = $minute*60; | |
$day = $hour*24; | |
$week = $day*7; | |
$month = $day*30; | |
$year = $day*365; | |
if ($time_diff <= 120) { | |
$output = "most"; | |
} elseif ($time_diff > $second && $time_diff < $minute) { | |
$output = round($time_diff/$second)." másodperce"; | |
} elseif ($time_diff >= $minute && $time_diff < $hour) { | |
$output = round($time_diff/$minute)." perce"; | |
} elseif ($time_diff >= $hour && $time_diff < $day) { | |
$output = round($time_diff/$hour)." órája"; | |
} elseif ($time_diff >= $day && $time_diff < $week) { | |
$output = round($time_diff/$day)." napja"; | |
} elseif ($time_diff >= $week && $time_diff < $month) { | |
$output = round($time_diff/$week)." hete"; | |
} elseif ($time_diff >= $month && $time_diff < $year) { | |
$output = round($time_diff/$month)." hónapja"; | |
} elseif ($time_diff >= $year && $time_diff < $year*10) { | |
$output = round($time_diff/$year)." éve"; | |
} else { | |
$output = " több, mint egy évtizede"; | |
} | |
*/ | |
/* | |
if ($output <> "now") { | |
$output = (substr($output,0,2)<>"1 ") ? $output."s" : $output; | |
$output .= " ago"; | |
} | |
*/ | |
$output = date("Y.m.d. H:i", $time); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment