I have a server app which is sent a date in the local format of the client
machine. I've no control over the client app at all, so have to code at the
server end to cope with any problems. The server is in the US, so any
dates need to be in US format before they will convert using strtotime()
Here is what i'm doing at the moment..
// need to convert date to use USA mm/dd/yyyy format on server
// $lt contains the date in the client format
$split = explode(",",$_SERVER[HTTP_ACCEPT_LANGUAGE]);
switch ($split[0]) {
case "en-us":
// already US format, so nothing to do
break;
case "en-gb":
// dd/mm/yyyy format
$lt = substr($lt,3,3) . substr($lt,0,3) . substr($lt,6);
break;
case "da":
case "pt":
// dd-mm-yyyy format
$lt = substr($lt,3,2) . "/" . substr($lt,0,2) . "/" . substr($lt,6);
break;
}
$ustime = strtotime($lt);
As you can see, the switch could get huge.. Is there an easier way ?
Thanks
Adrian