PDF (6.2M)

Localizing dates, times, and currencies

The way applications present dates, times, and currencies varies greatly for each locale. For example, the U.S. standard for representing dates is month/day/year, whereas the European standard for representing dates is day/month/year.

You can write code to format dates, times, and currencies. For example, the following code converts a Date object into month/day/year format or day/month/year format. if the locale variable (representing the locale) is set to "en_US", the function returns month/day/year format. The example converts a Date object into day/month/year format for all other locales:

function convertDate(date) 
{ 
    if (locale == "en_US") 
    { 
        return (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear(); 
    } 
    else 
    { 
        return date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear(); 
    } 
}