Re: Date Localization - Australian
| From: | Justin French | Date: | Thu, 01 May 2003 04:49:37 +0000 |
| Subject: | Re: Date Localization - Australian | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145904@lists.php.net to get a copy of this message | ||
Luke,
Please don't the same message over and over... people will answer it when/if
they can.
For starters, 20030430121556 doesn't look like a unix (epoch) timestamp to
me... it looks more like YYYYMMDDHHMMSS.
Secondly, I'm not sure your problem is directly related to locale.
For argument's sake, let's take a different approach:
<?
function formatDateFromStamp($stamp)
{
$year4 = substr($stamp,0,4);
$year2 = substr($stamp,2,2);
$month = substr($stamp,4,2);
$day = substr($stamp,6,2);
$hour = substr($stamp,8,2);
$min = substr($stamp,10,2);
$sec = substr($stamp,12,2);
if($hour >= 12) { $ampm = "pm"; } else { $ampm = "am"; }
return "{$day}/{$month}/{$year2} {$hour}:{$min}:{$sec}{$ampm}";
}
echo formatDateFromStamp('20030430121556');
?>
This will echo 30/04/03 12:15:56pm, which seems to be what you want -- why
do you need to go through mktime, and where is the locale issue?
Really, I'd be throwing away the stamps you're currently using, and just
using unix epoch time stamps (the number of seconds since 1970).
They can easily be obtained at any time in a script using time(), can easily
have a number of seconds added, subtracted and dived to them, are easily
compared (one is greater than the other, etc).
Better still, they're easily converted to human-readable dates using date():
echo date('d/m/y h:i:s a',$mystamp);
Anyway, I guess you should do a few inserts, and retrievals, to see how the
above function stacks up against the existing one... then if there's still a
locale issue, we can tackle that.
Justin French
on 01/05/03 4:11 PM, Luke Woollard (luke@taborvision.com) wrote:
> I need help with displaying an australian version of the current date and
> time.
>
> I've set the locale for my application using: setlocale (LC_ALL, 'en');
>
> Here is a class method I am using to return a date/time string
>
> /**
> * Displays a human-readable version of a unix timestamp.
> *
> * @access public
> * @param string timestamp A unix timestamp
> * @return string
> */
> function dateAndTime($timestamp)
> {
> // Parse input as a unix timestamp and list each part as separate
> variable
> list($year,$month,$day,$hour,$minute,$second) =
> sscanf($timestamp,"%4s%2s%2s%2s%2s%2s");
>
> // Return a formatted date/time according to our preferred locale
> return strftime('%c',
> mktime($hour,$minute,$second,$month,$day,$year));
> }
>
> Here is a sample command with a timestamp as input: echo
> dateAndTime('20030430121556');
>
> Here is output from the above command: 04/30/03 12:15:56 PM
>
> NOTE THAT THE DATE AND MONTH NEED TO BE INTERCHANGED!!!!!!!!
>
> Please help, this is driving me nuts.. I dont know how to set the locale
> speficically for Australia or if it is even possible with PHP..
>
>
>> Luke Woollard
>> .......................................................
>> Programmer / Analyst
>> TABORVISION
>> luke@taborvision.com
>> 03.9886.0881 ext 105
>> www.taborvision.com
>> .......................................................
>>
>> This document is confidential and may contain legally privileged
>> information. If you are not the intended recipient you must not copy,
>> distribute or act in reliance on it. The sender cannot guarantee that this
>> email or any attachment to it is free of computer viruses or other
>> conditions that may damage or interfere with data, hardware or software
> with
>> which it might be used. If you have received this document in error,
> please
>> advise us toll free on 1.800.50.50.42 Australia :: 973.556.1107 USA
>>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>