Reputation:
I have written a method using JSF:
public static String getCurrentTime(Locale locale) {
Calendar cal=Calendar.getInstance(locale);
return new SimpleDateFormat("HHmmss").format(cal.getTime());
}
While testing my application in my local machine I am getting the time same as system time but when my friends are testing it time delay is of 4 minutes.
What may be the problem? else suggest a code to do the same
Upvotes: 1
Views: 399
Reputation: 533520
You could check the computers both match a clock on the web like http://www.atomic-clock.org.uk/atomuhr.html
Upvotes: 0
Reputation: 73625
If you want the time to be accurate, synchronize the clocks of the computers with NTP.
Upvotes: 3
Reputation: 165242
This is happening because you are testing on two different machines - your system time is not the same.
The time is taken strictly from your local computer time. If you set the clock to 12:34, you will get 12:34, and not the real time.
Unless you connect to a time server on the network, or somehow manage to sync your clocks, you can never guarantee you will get the same time.
Alternatively, once you deploy your JSF application to a production server, you will always get the server time, which naturally is guaranteed to be correct for all users.
Upvotes: 4