Wrong time display

I wrote a method using JSF:

public static String getCurrentTime(Locale locale) {
        Calendar cal=Calendar.getInstance(locale);
        return new SimpleDateFormat("HHmmss").format(cal.getTime());
    }

      

When testing my application on my local machine, I get the same time as the system time, but when my friends test it, the delay time is 4 minutes.

What could be the problem? else suggest some code to accomplish the same

+1


source to share


3 answers


This is because you are testing on two different machines - your system time is not the same .

Time is taken strictly from the local computer. If you set the clock to 12:34, you get 12:34, not real time.



If you don't connect to an on-line time server or somehow sync your clock, you can never guarantee that you will get the same time.

Alternatively, once you deploy your JSF application to a production server, you always get server time, which is naturally guaranteed for all users.

+4


source


If you want the time to be accurate, synchronize your computers' clocks with NTP .



+3


source


You can check that computers match the clocks on the internet, for example http://www.atomic-clock.org.uk/atomuhr.html

0


source







All Articles