Displaying dates is always tricky if your site is being used by different people around the globe. There are different standards being used by various countries and you have to pay extra attention to correctly show dates in user’s locale date format. For example most of the countries in the world use DD/MM/YYYY, while MM/DD/YYYY is commonly used in North America. By sticking to one standard of displaying dates you might end up confusing your users. Therefore its always a good idea to display dates in the format your user expects it. In order to accomplish this you have to know where your user is located, in other words the ‘locale’ of the user.

dates{width=”859” height=”171”}

Locale of the user is usually sent to you by the browsers so you could process it on the backend and send proper data to your user. There are frameworks that have localization built into them to make your life easier like Zend or Rails. But remember that it is never 100% reliable.

The other option we have is to do it on the client’s browsers via JavaScript. Below is the code do just that:

var date, formattedDate;
// The date might come from your database and it is used to
// create differently formatted dates.
date = new Date("July 21, 2013");

// Format the date to use Arabic - United Arab Emirates
formattedDate = date.toLocaleString('ar-AE', {month: "long", day: "numeric", year: "numeric"});

// Format the date to use English - United States
formattedDate = date.toLocaleString('en-US', {month: "long", day: "numeric", year: "numeric"});

Be aware that toLocaleString() functionality is really browser dependent, while some browsers might have implemented it differently some actually does not even have it at all.