Search code examples
phpjavascriptdatelocale

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 me, I'll wait for some up-votes to see which approach you think is preferred


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"