Re: Military <-> Standard times

From: Date: Wed, 21 Jan 2009 21:06:39 +0000
Subject: Re: Military <-> Standard times
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-286955@lists.php.net to get a copy of this message
Jochem Maas wrote:
tedd schreef:
Hi gang:
would you stop calling me that, I'll bet it means something rude in korean. :-P
What's the slickest way to go from "standard" to military times and back again?
wouldn't the slickest way be to carry/store unixtimestamps and then output whatever version you need when you need it, the conversion back and forth *seems* pointless.
agree completely, seperate out the display so you have function militaryTime($t) { return strftime('%R', $t); } function standardTime($t) { return strftime('%r', $t); } $time = time(); $militaryTime = militaryTime($time); $standardTime = standardTime($time); = but then you could shorten to: function timeFormat($militaryTime = FALSE) { $format = $militaryTime ? '%R' : '%r'; return strftime($format, $t); } $time = time(); $militaryTime = timeFormat(TRUE); $standardTime = timeFormat(); = or you could leave you're options open and go for: function timeFormat($format = '%r') { return strftime($format, $t); } $time = time(); $militaryTime = timeFormat('%r'); = or just $time = time(); $militaryTime = strftime('%r', $time); :P

« previous php.general (#286955) next »