Home arrow static arrow Java Programming [Archive] - Date issues
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Date issues
This topic has 6 replies on 1 page.

Posts:397
Registered: 10/15/03
Date issues  
Jul 11, 2004 8:39 AM



 
Hi
My application is a swing client.as part of a process definition i need to set a scedule to the process.
I set the time as now with this function and the server also use with the exact same functions
whn working with dates.
The problem is when i set the date to now...and pass it to the server the return value is displayed in my computer as one hour erliear the the time set.
Please help me with that...Must find this bug a solution ASAP....\
Thanks in advance
Liat

public static Date getNow() {        //return new Date();        GregorianCalendar calendar = new GregorianCalendar();        return calendar.getTime();    }     public static String dateToString(Date date) {        return (DateFormat.getInstance()).format(date);    }     public static Date stringToDate(String formattedDate) throws BitBandBusinessException {        try {            return (DateFormat.getInstance()).parse(formattedDate);        } catch (ParseException e) {            if (log.isErrorEnabled())                log.error("Exception in parsing date");            throw new BitBandBusinessException("Exception in parsing date");        }    } 
 

Posts:6,147
Registered: 11/9/00
Re: Date issues  
Jul 11, 2004 9:53 AM (reply 1 of 6)



 
It's almost certainly a matter of conflicting Locale settings between client and server. Date is an international format, it stores times as GMT and DateFormat or Calendar translates that into your local time zone, using the Local setting passed or your system's default Locale setting.

Incidentally new Date() gives you the current time, you don't need to go through Calendar.
 

Posts:1,183
Registered: 1/23/02
Re: Date issues  
Jul 11, 2004 9:56 AM (reply 2 of 6)



 
... and pass it to the server

How do you pass it to the server? As a serialized Date object? As a serialized String?

Your problem is almost ceriatinly a mismatch in default TimeZones between the server and the client.
 

Posts:397
Registered: 10/15/03
Re: Date issues  
Jul 11, 2004 11:07 PM (reply 3 of 6)



 
I pass the date as a long number.(as part of a serialized object)
We all decided to use this calendar in oreder to have the same date format....
and prevent this kind of problems.
all computers are set to the same time zone....
 

Posts:1,160
Registered: 7/24/97
Re: Date issues  
Jul 12, 2004 12:33 AM (reply 4 of 6)



 
I have had similar problems with a web application, in this case I had to assume that the actual Locale and Timezone were unknown because the client machine could be anywhere in the world.

To solve the problem I passed Dates around as Strings using a Locale neutral format and parsed them
on the Server.
 

Posts:397
Registered: 10/15/03
Re: Date issues  
Jul 12, 2004 12:35 AM (reply 5 of 6)



 
what do u mean by that:
Locale neutral format ? how do u commite the parsing? can u give me an example ofthat code?
 

Posts:6,147
Registered: 11/9/00
Re: Date issues  
Jul 12, 2004 1:06 AM (reply 6 of 6)



 
all computers are set to the same time zone....

Try using an explicit Locale for your DateFormat objects.

 
This topic has 6 replies on 1 page.