Trying to store fixed dates in calendar....

  • Thread starter =?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=
  • Start date
?

=?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=

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
 
M

Michael Borgwardt

Pierre-Yves Landuré said:
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.
 
?

=?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=

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
 
M

Michael Borgwardt

Pierre-Yves Landuré said:
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.
 
?

=?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=

ok, sorry for my first incoherent and stupid post.

i've digged into my problem, and now i can describe it correctly ;)

well, i'm using Calendar to store dates.
when during my process i'm not accessing to the stored date, the code
works well....

but ! if i access to the stored date more than one time, the second time
i access the date, (via for example the getTimeInMillis() method), the
date would have change :
the year, month and day value would keep being correct, but the hours ,
minutes ,secondes and milliseconds would have been set to the system ones.

I want to precise that i don't use any set on the calendar in the used
code after the calendar first initialisation.

is my problem description clearer ?
how can i fix this problem ?

thanx for help

pierre-yves landuré
 
H

Harald Hein

Pierre-Yves Landuré said:
is my problem description clearer ?

You have been told to show us complete, readable code (your's is not
readable). You ignored that advice.
how can i fix this problem ?

You have been told that Calendar is the wrong class to store fixed
dates (guess why it is called Calendar and not Date?). You have ignored
that advice. What is your problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top