Automated date formatting based on browsers locale / location
I am looking for solution in javascript or PHP which format "date" and "time" based on the visitors location and locale settings.
For example
echo auto_format_date(time());
would output 20-09-2011 for users from states and 20/09/2011 for UK users.
Thanks everyone for answers. I've got now several alternatives in front of 开发者_如何学JAVAme, I'll wait for some up-votes to see which approach you think is preferred
In server side code (PHP, ASP.NET...) you can check Accept-Language
HTTP header of request to detect client browser language.
Accept-Language: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
You can read additional info: http://www.w3.org/International/questions/qa-accept-lang-locales
You have to get Country from Ip by PHP Geolacator
and than use zned function: date_default_timezone_set('Europe/Berlin');
and when you create date:
$date = new Zend_Date();
echo $date;
You will get what you want...
I have found the following myself:
http://www.w3schools.com/jsref/jsref_tolocalestring.asp
which might help me format date into user's preferred format once it in the browser. Is this a good solution?
I found another answer, which relies on datejs
https://code.google.com/p/datejs/wiki/FormatSpecifiers
%x preferred date representation for the current locale
without the time "4/13/2008"
%X preferred time representation for the current locale
without the date "12:53:05"
精彩评论