Trying to store fixed dates in calendar....  
Author Message
Pierre-Yves Landur





PostPosted: 2003-10-17 17:08:00 Top

java-programmer, Trying to store fixed dates in calendar.... hi,

sorry to bother you with a question somebody should have already ask,
but i was unable to find it in groups.google.com.. so ;)=

well, my problem is that i'm trying to store dates values in Calendar
(more exactly GregorianCalendar) class instances.

BUT... the stored dates keep on running upon the system date :

ie : i store 2h 34m 5s 324ms

4s later, when i print the date, it will give me something like

2h 34m 9s 450ms

it is very bothering for me...

how can i make Calendar class to store "fixed" dates... ?

or which class should i use to store "fixed" dates ?

Thanx for your help.

Pierre-Yves

 
Michael Borgwardt





PostPosted: 2003-10-17 17:45:00 Top

java-programmer >> Trying to store fixed dates in calendar.... Pierre-Yves Landur?wrote:
> hi,
>
> sorry to bother you with a question somebody should have already ask,
> but i was unable to find it in groups.google.com.. so ;)=
>
> well, my problem is that i'm trying to store dates values in Calendar
> (more exactly GregorianCalendar) class instances.
>
> BUT... the stored dates keep on running upon the system date :
> ie : i store 2h 34m 5s 324ms
> 4s later, when i print the date, it will give me something like
> 2h 34m 9s 450ms
> it is very bothering for me...
>
> how can i make Calendar class to store "fixed" dates... ?
> or which class should i use to store "fixed" dates ?

You're doing something wrong, but we can't tell without seeing your code.

However, the Date class is usually used to store dates, not a Calendar class.

 
Pierre-Yves Landur





PostPosted: 2003-10-17 17:47:00 Top

java-programmer >> Trying to store fixed dates in calendar.... Oups.. sorry, forgetting to put the code :

here it goes :

private static Calendar toCalendar(int dayFromUtc58, int
secondsWithinDay, int microsecondsWithinSecond) {
GregorianCalendar jasonCalendar = new
GregorianCalendar(DiaSatConstants.TIME_ZONE, DiaSatConstants.LOCALE);
GregorianCalendar calendar58 = new
GregorianCalendar(DiaSatConstants.TIME_ZONE, DiaSatConstants.LOCALE);

calendar58.set(Calendar.YEAR, JASON_UTC);

long ldayFromUtc58 = dayFromUtc58;
long lsecondsWithinDay = secondsWithinDay;
long lmicrosecondsWithinSecond = microsecondsWithinSecond;

jasonCalendar.setTimeInMillis((ldayFromUtc58 * 24 * 60 * 60 *
1000) + (lsecondsWithinDay * 1000) + (lmicrosecondsWithinSecond / 1000)
+ calendar58.getTimeInMillis());

return jasonCalendar;
}


this method get a date exprimed in days from 1/1/1958
i'm using Calendar.setTimeInMillis to set the time value.

Thanx for help

Pierre-Yves


Michael Borgwardt wrote:
> Pierre-Yves Landur?wrote:
>
>> hi,
>>
>> sorry to bother you with a question somebody should have already ask,
>> but i was unable to find it in groups.google.com.. so ;)=
>>
>> well, my problem is that i'm trying to store dates values in Calendar
>> (more exactly GregorianCalendar) class instances.
>>
>> BUT... the stored dates keep on running upon the system date :
>> ie : i store 2h 34m 5s 324ms
>> 4s later, when i print the date, it will give me something like
>> 2h 34m 9s 450ms
>> it is very bothering for me...
>>
>> how can i make Calendar class to store "fixed" dates... ?
>> or which class should i use to store "fixed" dates ?
>
>
> You're doing something wrong, but we can't tell without seeing your code.
>
> However, the Date class is usually used to store dates, not a Calendar
> class.
>
>

 
 
Michael Borgwardt





PostPosted: 2003-10-17 19:41:00 Top

java-programmer >> Trying to store fixed dates in calendar.... Pierre-Yves Landur?wrote:
> private static Calendar toCalendar(int dayFromUtc58, int
> secondsWithinDay, int microsecondsWithinSecond) {
> GregorianCalendar jasonCalendar = new
> GregorianCalendar(DiaSatConstants.TIME_ZONE, DiaSatConstants.LOCALE);
> GregorianCalendar calendar58 = new
> GregorianCalendar(DiaSatConstants.TIME_ZONE, DiaSatConstants.LOCALE);
>
> calendar58.set(Calendar.YEAR, JASON_UTC);
>
> long ldayFromUtc58 = dayFromUtc58;
> long lsecondsWithinDay = secondsWithinDay;
> long lmicrosecondsWithinSecond = microsecondsWithinSecond;
>
> jasonCalendar.setTimeInMillis((ldayFromUtc58 * 24 * 60 * 60 *
> 1000) + (lsecondsWithinDay * 1000) + (lmicrosecondsWithinSecond / 1000)
> + calendar58.getTimeInMillis());
>
> return jasonCalendar;
> }

Are you trying for an obfuscated code competition? That's absolutely
*awful* code that I don't have the time to try and understand.

> this method get a date exprimed in days from 1/1/1958

Then you should use the add() method of the Calendar class, it will make your
code much simpler and probably the error will disappear.