Re: Military <-> Standard times
| From: | Jochem Maas | Date: | Wed, 21 Jan 2009 20:19:08 +0000 |
| Subject: | Re: Military <-> Standard times | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-286941@lists.php.net to get a copy of this message | ||
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.
>
> Such as:
>
> 0800 -> 8:00am
> 8:00am -> 0800
>
> -- or --
>
> 1600 -> 4:00pm
> 4:00pm -> 1600
>
> I use the following functions, but is there anything better?
>
> function standardToMilitary($t)
> {
> $t = strftime('%R', strtotime($t));
> return $t;
what's with the superfluous variable?
why not just:
return strftime('%R', strtotime($t));
also, small point, if you came across the function
militaryToStandard() somewhere in the code, how would
one know if it were all about about time formats
or elephants?
> }
>
> function militaryToStandard($t)
> {
> $t = strftime('%r', strtotime($t));
> return $t;
> }
>
> Thanks,
>
> tedd
PS - I think the best ever name for a Exception class is 'Tantrum':
throw new Tantrum('Ra Ra Ra Aaaargh');