Trying to store fixed dates in calendar....

Discussion in 'Java' started by =?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=, Oct 17, 2003.

  1. 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
    =?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=, Oct 17, 2003
    #1
    1. Advertising

  2. 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, Oct 17, 2003
    #2
    1. Advertising

  3. 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.
    >
    >
    =?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=, Oct 17, 2003
    #3
  4. 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.
    Michael Borgwardt, Oct 17, 2003
    #4
  5. Re: Trying to store fixed dates in calendar.... : problem redefinition

    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é




    Michael Borgwardt wrote:
    > 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.
    >
    >
    =?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=, Oct 17, 2003
    #5
  6. =?ISO-8859-1?Q?Pierre-Yves_Landur=E9?=

    Harald Hein Guest

    Re: Trying to store fixed dates in calendar.... : problem redefinition

    "Pierre-Yves Landuré" wrote:

    > 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?
    Harald Hein, Oct 19, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    859
    Rob Schieber
    Sep 30, 2005
  2. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    189
    Mark Schupp
    Aug 9, 2004
  3. Replies:
    1
    Views:
    203
    Jano Svitok
    Jul 17, 2007
  4. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    189
    Eric I.
    Jun 8, 2008
  5. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    155
    Dr J R Stockton
    Jun 18, 2007
Loading...

Share This Page