Manage time zones easily in your application
This blog post tells about the most popular date- and time-related issues our clients reported while analyzing data from databases, CSV, or JSON. We are happy to suggest a new simple approach which helps to manage time zones effectively. Let’s analyze the most popular use cases:
Case 1. Compressor changing the dates to one day less than the actual value from the database
This happens because Compressor sends date in UTC time zone. On the client side, the same time is shown but in the local time zone. Such time-shift can result in a surprising effect: dates are one day less than expected.
Case 2. End-users see different time in Flexmonster Component when changing time zones
When Flexmonster displays date and time, it takes into account local time zone. This leads to a situation when different users might look at the same report and see different time.
Case 3. Time shown in Pivot Component differs from time in database or file
Most often such issue occurs when server and clients are located in different time zones, which can cause time to be displayed in a wrong time zone.
How to manage such situations in Flexmonster?
We have two special properties, datePattern
and dateTimePattern
, that affect representation format of dates and time inside the component. If you haven’t used Flexmonster patterns before, please visit our Date and time formatting tutorial.
Starting from version 2.415, we extended patterns functionality. Use datePattern
and dateTimePattern
to set the time zone, which will affect time displayed on the grid. For instance, to specify a GMT+5
time zone, set your pattern as "GMT+5:dd/MM/yyyy"
. Time zone is defined by GMT+-N:
prefix, where N
can take values from 1 to 12. This allows converting the dates in the time zone you specify.
For those our clients who use Compressor for Java or PHP, we have one more option to manage date and time. By default, all the dates are converted in UTC time zone. Now you can use Compressor.timeZone
(Java) or Compressor::TIME_ZONE
(PHP) property to set another time zone for parsing data directly in Compressor. Please note, time zone should be specified in the standard format for chosen technology and the data is still returned in UTC.
We hope the approach introduced in this post will help you to display date and time easily.
Want to share your thoughts and comments? Our team would be happy to read them. Here is the Contact form.