Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Time wrong in java programs

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java has no idea what time it is. It asks the machine it is running on for the time. So check that first.
 
Eric Michael
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 am going to test your electrical conductivity with this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic