Date and Time Problems in Programming


Since the world is globe, we can experience different time zones. Time zone is man-made concept used represent the time by based on their regional basis. Therefore, when we experience sun rising as Sri Lankan, another country (like America) may faced sun set. However, this characteristic provides problems in programming and it is the problem we must need to consider when we work with sensitive data in application development.

For an example, let’s say we have developed a system for hospital to record birth details of new born babies in Sri Lanka. They enter birth time by based on Sri Lankan standard time. Just think that one baby was born in 3rd April at 7 A.M. If this detail is viewed by American person he/she will this “Ok one baby is going to be born in 3rd April”. Because, America is behind from us nearly 11.30 hours. So, although it’s 3rd April 7 P.M in Sri Lanka, the date and time in America would be around 2nd April 6.30 P.M.

In order to avoid this problem, we can use UTC (Coordinated Universal Time) format.

UTC (Coordinated Universal Time)

UTC provides regular time zone for whole world and furthermore treated as Standard time. In this UTC format consists with offset numbers which can be both positive and negative.


For an instance, Sri Lanka is in the plus 5.30 time zone UTC. That means it is 5.30 hours greater in Sri Lanka than the reading on a UTC clock.

Also, UTC 0 offset belongs to Greenwich Mean Time (GMT). From offset 0 onwards, different countries and regions can have same off set values but in different direction as plus or minus.

What is Day Light Saving?

This concept is introduced by George Hudson in 1895 to hunting time in spring vacations. The European countries like U.S.A, U.K, Canada, etc use this day light concept in summer months to increase the working hours since the darkness falls at later of hours. Also time is set back in to the standard format when the Autumn begins.

Let’s See How Can We Deal With Data and Time Problems in Java

The developers have to be very careful regarding this date-time problems when develop applications. So, it may not be cause danger when their developed application is used within the same time zone. But, when it is different it can provides really weird outputs.

Fortunately, Java 8 implements enhanced time package to handle time zone as well day light problems. You can use java.time and packages to make your applications working over the different time zones. Let’s see some of Java date, time classes.

1. LocaDate, LocalTime and LocalDateTime classes:

LocalDate class provides the current date of the dat while LocalTime provides current time of the day. The LocalDateTime is combination of LocalDate and Time classes. But, this class is not responsible to deal over different time zones.

2.Instant class:

java.time.Instance holds date, time values respect to the UTC.


When we are dealing with the date, time objects over the time zones, then we must need to use this class in order to manipulate our inputs.


It provides unique IDs over time zones.


It provides unique identifier for time zones and represents offset of time zone in UTC or GWT formats.

Below shows some of uses of the first 3 classes in date and time considerations in java.

Hope you can get a clear understand about date and time problem in programming and how can we avoid these problems.

Stay Safe!!!





Associate Software Engineer at Virtusa.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Yes, Google it.

Zowe On The Go: A Mobile Application For Modern Mainframers

The Value of a Good Technical Demo

10 useful VS Code extensions to Make Life Easier ーPart- 5

4 Steps to Linux Sub-System in Windows 10

What is OOP? In Layman terms…

Top 20 Kubernetes Interview Questions !!!.

Development Summary 2020

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sanduni Jayaweera

Sanduni Jayaweera

Associate Software Engineer at Virtusa.

More from Medium

Understanding A Woman’s Body Language & Interest Signals and Why Women Flake And Exactly What To Do…

Essay Reflection #1- Mindy Condon

Computer Says “No”

The Importance of Being Nice