1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Windows 7 and Java getTime function

Discussion in 'Software Development' started by esokol, Jul 17, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. esokol

    esokol Thread Starter

    Joined:
    Jul 17, 2012
    Messages:
    2
    I am running on Windows 7 Professional, Service Pack 1, 64 bit. I am also using Java 1.4.02_08 (old but serviceable for our purposes).

    When I run my code on XP, the variable todayTime using the Java getTime() function returns the correct local time - namely the time which shows on my computer clock which is GMT-06 (Central time USA).

    I recently upgraded to Windows 7 and running the same code, the variable todayTime using the Java getTime() function returns GMT time not the local time shown on the computer. I have looked at the computer clock during restart and the BIOS shows the correct local time.

    My question - what do I need to do to get the Java function to work with Windows 7?

    Here's the code snippet:
    Calendar today = Calendar.getInstance();
    SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy");
    String defaultDate = dateformat.format(today.getTime());
    SimpleDateFormat timeformat = new SimpleDateFormat("hh:mm a");
    java.util.Date todayTime = today.getTime();
    String defaultTime = timeformat.format(todayTime);

    Thanks in advance.
     
  2. Popa Mintin

    Popa Mintin

    Joined:
    Jun 25, 2008
    Messages:
    25
    I recall having a similar problem some while back and it turned out to be that I'd not set the correct options in: -
    Start> Control Panel> Region and Language.
    Once I corrected that, all my date n time functions worked as expected.

    Popa.
     
  3. esokol

    esokol Thread Starter

    Joined:
    Jul 17, 2012
    Messages:
    2
    My regional setting were correct. Thanks for the suggestion.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1061476