Configure time zones and locale

Summary #

By default Liferay sets the time zone to "GMT" (UTC) and the locale to "en_US". You can change these defaults by following the steps below.

In the examples below we are adding the Australian time zones and assuming the default time zone is "Australia/Perth" (GMT+8). Also, we are assuming the default locale is "en_AU" (Australian English). Please change these values to meet your own requirements.

Locations of the "portal-ext.properties" and "system-ext.properties" files referenced below vary between installations. If you are using the Liferay+Tomcat, you can create the files in your Tomcat home (the folder which contains /data /deploy /tomcat-version). If you are unsure consult the Liferay admin guide.

How to change / add time zones #

Create/update "portal-ext.properties" with a comma-separated list of the time zones you wish to use.

eg,

time.zones=\ 
   Australia/Perth,\
   Australia/Adelaide,\
   Australia/Darwin,\
   Australia/Brisbane,\
   Australia/Canberra,\
   Australia/Hobart,\
   Australia/Melbourne,\
   Australia/Sydney

How to set the default timezone #

Create/update "system-ext.properties" and set the default time zone

eg. 

user.timezone=Australia/Perth

Alternatively, you can add your new timezones to the existing values:

time.zones=\
        Pacific/Midway,\
        Pacific/Honolulu,\
        America/Anchorage,\
        America/Los_Angeles,\
        America/Denver,\
        America/Chicago,\
        America/New_York,\
        America/Caracas,\
        America/Puerto_Rico,\
        America/St_Johns,\
        America/Sao_Paulo,\
        America/Noronha,\
        Atlantic/Azores,\
        UTC,\
        Europe/Lisbon,\
        Europe/Paris,\
        Europe/Istanbul,\
        Asia/Jerusalem,\
        Asia/Baghdad,\
        Asia/Tehran,\
        Asia/Dubai,\
        Asia/Kabul,\
        Asia/Karachi,\
        Asia/Calcutta,\
        Asia/Katmandu,\
        Asia/Dhaka,\
        Asia/Rangoon,\
        Asia/Saigon,\
        Asia/Shanghai,\
        Asia/Tokyo,\
        Asia/Seoul,\
        Australia/Perth,\ 
        Australia/Adelaide,\ 
        Australia/Darwin,\ 
        Australia/Brisbane,\ 
        Australia/Canberra,\ 
        Australia/Hobart,\ 
        Australia/Melbourne,\ 
        Australia/Sydney,\
        Pacific/Guadalcanal,\
        Pacific/Auckland,\
        Pacific/Enderbury,\
        Pacific/Kiritimati


=== How to add / update locales ===

Create/update "portal-ext.properties" with a comma-separated list of the locales you wish to use.

eg.

locales=en_AU

Alternatively you can add your new locale to the existing locales

eg.

locales=ar_SA,eu_ES,bg_BG,ca_AD,ca_ES,zh_CN,zh_TW,cs_CZ,nl_NL,en_AU,en_US,en_
GB,et_EE,fi_FI,fr_FR,gl_ES,de_DE,el_GR,iw_IL,hi_IN,hu_HU,in_ID,it_IT,ja_JP,ko_KR,nb_NO,fa_IR,pl_PL,pt_BR,pt_PT,ru_RU,sk_SK,es_ES,sv_SE,tr_TR,uk_UA,vi_VN

Also remember to add new locales as URL patterns for the "I18n Servlet" in web descriptor file "ROOT/WEB-INF/web.xml".

The following snippet shows how to add the Australian English (en_AU) as a new URL pattern.

<servlet-mapping>
   <servlet-name>I18n Servlet</servlet-name>
   <url-pattern>/en_AU/*</url-pattern>    
</servlet-mapping>   

How to set the default locale #

Create/update "system-ext.properties" and set the default user locale.

eg.

user.country=AU
user.language=en

Common Issues / Important Notes #

When Liferay starts for the first time, it creates a default user for the company. This user is assigned the time zone obtained from "system.properties" and the value of "user.timezone". 

CompanyLocalServiceImpl#checkCompany(String webId, String mx, String shardName

The data stored for the default user(s) can be viewed by running this SQL snippet:

select * from User_ where defaultuser = 1;

The default user is not visible in the Control Panel but it is possible to edit the default user's time zone using "Control Panel > Portal > Settings > Miscellaneous > Display Settings > Time Zone".

Whenever a new user is created, it is assigned the current time zone of the default user, irrespective of the current value of the "user.timezone" system property.

UserLocalServiceImpl#addUser()

If Liferay has already been installed, it will be configured with previous "user.timezone" and "user.locale" settings.

These values are typically "user.timezone=GMT" and "user.locale=en_US".

You can update these values for your required timezone and locale by running these SQL snippets against your Liferay database instance:

eg. update only default user timezones to Perth, Western Australia

update User_ set timezoneid = 'Australia/Perth' where defaultuser = 1;

eg. update all user timezones to Perth, Western Australia

update User_ set timezoneid = 'Australia/Perth';

eg. update only default user language ID to Perth, Western Australia

update User_ set languageid = 'en_AU' where defaultuser = 1;

eg. update all user language IDS to Australian English

update User_ set languageid = 'en_AU';

NOTE: Replace the timezone and language IDs to suit your locale timezone and language ID.

NOTE: It is best practice to set your required "systen-ext.properties" and "portal-ext.properties" before you first run Liferay so that the defaults are setup correctly. Otherwise some things are stored in the database and can't be changed without database manipulation.

JVM Locale and Time Zone Settings #

Note: Liferay will not pickup your JVM time zone and locale settings. See http://issues.liferay.com/browse/LEP-2584

Friendly URLs #

In some situations, you can end up with your new locale prepended to URLs in Liferay

i.e.

http://localhost:8080/en_AU/web/guest/home

This is a feature.

However, if you want to disable it you can set the following property in "portal-ext.properties".

eg.

locale.prepend.friendly.url.style=0

Add Non-Standard Timezones #

 Note that the specified new timezone ids must match those from the class java.util.TimeZone, that may meet most of requires, but if you still want to add a non-standard timezone or want to show a different TimeZone name, then can follow these steps:  

1.  Add your TimezoneID in portal-ext.properties file: 

         For example: I add "Australia/WST'(+07:30)" in portal-ext.properties            

time.zones=\  
                Asia/Saigon,\
                Australia/WST,\ 
                Asia/Shanghai,\

2.  Update  html\taglib\ui\input_time_zone\page.jsp  in your ext environment: 

 <%
    for (int i = 0; i < timeZones.length; i++) {
       if(timeZones[i].equals("Australia/WST")){
 %>
          <option <%= value.equals("Australia/WST") ? "selected" : "" %> value="Australia/WST">(UTC +07:30) <%= LanguageUtil.get(pageContext, "australia-wst") %></option>
 <%
       }
       else{
          //original code here
          <option <%= value.equals(curTimeZone.getID()) ? "selected" : "" %> value="<%= curTimeZone.getID() %>">(UTC <%= offset %>) <%= curTimeZone.getDisplayName(daylight, displayStyle, locale) %></option>
 <%
       }
   }
 %>
0 Attachments
37771 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
Threaded Replies Author Date
Thanks to Terry Mueller, Tim Telcik and John... Scott Palmer June 14, 2011 7:45 PM
I was not able to make this work with... Fabio Moratti April 30, 2013 7:05 AM
I think the issue is you also need to be... Scott Palmer May 13, 2013 12:47 AM

Thanks to Terry Mueller, Tim Telcik and John Wen for components of this contribution (http://www.permeance.com.au/web/terry.mueller/home/-/blogs/how-to-use-time-zone­s-with-liferay-portal and http://www.liferay.com/community/wiki/-/wiki/1071674/Using+a+Locale+other+than+E­nglish+%28en_US%29/maximized).
Posted on 6/14/11 7:45 PM.
I was not able to make this work with liferay-portal-6.1.20-ee-ga2.

I added system-ext.properties file with
# ------------------------------------------------
user.timezone=Europe/Paris
user.c­ountry=IT
user.language=it
# ------------------------------------------------
before starting up for the first time.

The properties are correctly read (checked via JMX) but the timezoneId and languageId in the table User_ are always created at the default values (GMT / en_US ).

The only way it worked for me was to change the value via Control Panel in

Portal -> Portal Settings -> Miscellaneous -> Display Settings -> Time zone

and in

My Account -> Miscellaneous -> Display Settings -> Time zone
Posted on 4/30/13 7:05 AM.
I think the issue is you also need to be updating your portal-ext.properties file. From memory that defaults to en_US unless you change it. So what's probably happening is your portal.properties included in the portal-impl.jar is being loaded and defaulting to en_US and the default timezone. Set the relevant settings in portal-ext.properties and try again.
Posted on 5/13/13 12:47 AM in reply to Fabio Moratti.