MyBB Community Forums

Full Version: How to display local time with am/pm
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
how can display time to my local display not am/pm but according to my local settings?
(In Greek settings πμ/μμ)
This depends on the php function date() and how the server is configured. If the server is confused to be an English server that's what it'll use to output.
Thanks is there any other way to display correct. I saw something like that in SMF
I think MyBB should implement translation of am/pm, and month names maybe. It isn't exactly too easy for the setlocale function to work correctly (as it requires usage of strftime). Better to use few str_replaces and convert them on the fly.

Anyways, dyrer, you just need it for am/pm right? Then try the following:

Open inc/functions.php and find:
	$plugins->run_hooks_by_ref("my_date", $date);

Add below:
$date = str_replace(array('am', 'pm'), array('πμ', 'μμ'), $date);

However, you'll have to make sure the text editor you're using is saving it in unicode utf-8 format.

Or another way is to find:
$date = gmdate($format, $stamp + ($offset * 3600));

and replace with:
                setlocale(LC_TIME, 'el_GR.UTF-8', 'el_GR');
                // code from ExoHelpDesk 1.3 in dev
		$format = str_replace(
					array('F', 'M',  'm','d', 'D', 'l', 'Y', 'y', 'H', 'h', 'i', 'a', 'A', 's'), 
					array('%B','%b','%m','%d','%a','%A','%Y','%y','%H','%I','%M','%p','%p', '%S'), 
				  $format);
                $date = gmstrftime($format, $stamp + ($offset * 3600));

Not sure if second way will work good though.