Legacy Knowledge Base
Published Sep. 10, 2025

Does the Timezone Needs to be Converted Manually When Fetching Database Entries Programmatically?

Written By

Kenny Back

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • We changed the default timezone by doing the following:
1. Instance settings > localization > time zone > change to eastern daylight time
2. User Account settings > preferences > display settings > change to eastern daylight time
  • But now we have a question regarding custom code in this context - if we are fetching some entries from the database programmatically then are we required to convert the time manually or will it convert automatically?

Environment

  • 2023.Q4.8

Resolution

  • The database always stores as GMT and it is up to the developer to display in the appropriate timezone. So to handle that, you will need to provide the conversion, but there are facilities in Liferay to assist with this. For example, for web content, to display the article display date, you could use code similar to:
<%
Format dateFormat = FastDateFormatFactoryUtil.getDateTime(themeDisplay.getLocale(), themeDisplay.getTimeZone());
%>
<p>Display Date: <%= dateFormat.format(article.getDisplayDate()) %></p>
  • This code uses the FastDateFormatFactoryUtil to get an instance of format that is set with the user's locale and user's timezone. When it is formatting the actual date, which is in GMT, the formatter converts to the user's local timezone and displays it in the manner expected. 

  • The portal leverages this kind of logic everywhere. The ThemeDisplay will be set up with the appropriate locale and timezone on a request-by-request basis and will be set to the user's timezone (if you have one assigned), falling back to the company timezone (if the user doesn't have one), so this technique outlined here will always give appropriate results. The FastDateFormatFactoryUtil has a number of different getDateTime() methods that take arguments to control formatting aspects (i.e. short dates vs long dates, etc) so there's lots of control available on how you want to control presentation.

 

 

 

Did this article resolve your issue ?

Legacy Knowledge Base