• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help on Time conversion.

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am in U.S. Eastern Standard Time Zone (4 hours behind GMT during daylight savings time, or 5 hours behind GMT during eastern standard time).

My web application is running on Weblogic server, the server is using GMT system time zone.

I need to convert input from UI, which is in EST String format ( "9/1/2005 00:00"), to GMT Timestamp object (9/1/2005 04:00).

How can I do it? I tried this and it did not work:

import java.util.*;
import java.text.SimpleDateFormat;

public class TZ1 {
public static void main(String[] args) {

TimeZone tz = TimeZone.getTimeZone("US/Eastern");
TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone("GMT");

Calendar estCalendar = Calendar.getInstance(tz);
Calendar gmtCalendar = Calendar.getInstance(GMT_TIME_ZONE);

String dateString = "9/1/2005";
String formatString = "MM/dd/yyyy";

SimpleDateFormat eptDateFormat = new SimpleDateFormat(formatString);
eptDateFormat.setTimeZone(tz);

SimpleDateFormat gmtDateFormat = new SimpleDateFormat(formatString);
gmtDateFormat.setTimeZone(GMT_TIME_ZONE);

try {
System.out.println("dateString is: " + dateString);

//Date resultDate1 = eptDateFormat.parse(dateString);
//System.out.println("resultDate1 is: " + resultDate1);

Date resultDate2 = gmtDateFormat.parse(dateString);
System.out.println("resultDate2 is: " + resultDate2);

} catch (Exception e) {

}

}
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I tried this and it did not work:



What does this mean? What output did you get?


} catch (Exception e) {

}



It's almost never a good idea to ignore exceptions you're catching without at least generating a message that an exception was thrown - especially when working on a program that does not (yet) work correctly.
[ August 22, 2005: Message edited by: Ulf Dittmer ]
 
Kate Xu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got an output, but it was not what I expected:

dateString is: 9/1/2005
resultDate2 is: Wed Aug 31 20:00:00 EDT 2005

I expected resultDate2 to be: Thu Sep 1 04:00:00 GMT 2005
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a lot going on there but let's get to the core issue. Regardless of what value you have in resultDate2, if you are getting EDT then the system's using EDT not GMT.

>> System.out.println("resultDate2 is: " + resultDate2);

The key here is that Date values are effectively absolute. They never carry timezone or formatting information. Try a simple one-line program that prints the date.
 
reply
    Bookmark Topic Watch Topic
  • New Topic