File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Time wrong in java programs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Time wrong in java programs" Watch "Time wrong in java programs" New topic
Author

Time wrong in java programs

Eric Michael
Greenhorn

Joined: Oct 07, 2002
Posts: 9
I'm running Java on a Win 98 machine. When I run a Java application or view a JSP page, Java thinks that the time is one hour in the past. What could be causing this? How can I fix it?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Present us with a small test program (source code) which gives the wrong time on your system, and we'll take a look. I can at least check it on Me/2000/NT.
I noticed you said JSP. That's running on a server
somewhere - is its time set correctly?
Is it a daylight-saving problem?
Dunno...


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Java has no idea what time it is. It asks the machine it is running on for the time. So check that first.


Please ignore post, I have no idea what I am talking about.
Eric Michael
Greenhorn

Joined: Oct 07, 2002
Posts: 9
Here is an example of a stand-alone Java program that prints the time as one hour in the past on my Win 98 system:
import java.util.*;
public class TimeTest {
public static void main(String args[])
{
Date a = new Date();
System.out.println(a);
}
}
The clock on my Win 98 toolbar gives the correct time. I also see this error when I run a JSP page with JRun or Tomcat, and also when I run the test simulator that comes with the Sybex book.
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
It is most likely timezone / daylight savings related. Have a look at the following classes for more information on how to influence the timezone for output:
http://java.sun.com/j2se/1.4.1/docs/api/java/util/Calendar.html
http://java.sun.com/j2se/1.4.1/docs/api/java/util/TimeZone.html
http://java.sun.com/j2se/1.4.1/docs/api/java/text/DateFormat.html
http://java.sun.com/j2se/1.4.1/docs/api/java/text/SimpleDateFormat.html
I would suggest modifying the time output format to include the timezone being used.
Cheers, Neil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Time wrong in java programs