7 Replies Latest reply: Aug 31, 2007 8:50 AM by 807605 RSS

    Regarding java.util.date / simple date format

    807605
      Hi Friends,

      I have a weired requirement where I am suppose to get time in millisecond for 3 scenarios.

      1. next 07:00 time
      2. next monday 07:00
      3. on next 1st 07:00

      Swing provides some jar where I can get next day - but not sure if I can play around to get my data.

      need your inputs.

      appreciate your quick reply friends,

      Chintan

      P.S. the reason I have to do so is

      1. I have 3 kind of reports - few reports expire daily - few weekly - few monthly.
      2. I am going to fetch the report from the external system and store (cache) in my db.
      3. Administrator can configure that when exactly the report is going to be updated in external system.
      4. So lets say for daily - every day at 7 it will be updated - so when I read the cached data, I want to compare the stored time stamp with next 7:00 time stamp and if my stored timestamp is less than next 7:00 time stamp - i can use the cached data and similarly for weekly and monthly.

      Please let me know if you have more questions.
        • 1. Re: Regarding java.util.date / simple date format
          807605
          I'll just add an example.

          say I added a report to DB at 1188563489217 and my cutoff is weekly that is on next monday at 7:00 in the morning - at that time my milliseconds would be 1188783033888

          now as far as my stored milliseconds are less than 1188783033888 i can read it from my db and if my stored milliseconds are greater than 1188783033888 then I need to refetch the report.

          Now for this task - every time i make a call to my DB - i have to get time in milli seconds for next monday 7:00.

          Is it possible??

          I am badly struck over here - please guide.

          Chintan

          Appreciate your help buddies.

          Chintan
          • 2. Re: Regarding java.util.date / simple date format
            807605
            read the API on java.util.Date en java.util.Calendar
            • 3. Re: Regarding java.util.date / simple date format
              807605
              I'll just add an example.

              say I added a report to DB at 1188563489217 and my
              cutoff is weekly that is on next monday at 7:00 in
              the morning - at that time my milliseconds would be
              1188783033888

              now as far as my stored milliseconds are less than
              1188783033888 i can read it from my db and if my
              stored milliseconds are greater than 1188783033888
              then I need to refetch the report.

              Now for this task - every time i make a call to my DB
              - i have to get time in milli seconds for next monday
              7:00.

              Is it possible??

              I am badly struck over here - please guide.

              Chintan

              Appreciate your help buddies.

              Chintan
              Take the hint if the date string is 35:11:2007 07:00 in dd:MM:yyyy HH:mm format then the parsed date will be 05:12:2007 07:00.

              your problem is actually a piece of cake ;-)
              • 4. Re: Regarding java.util.date / simple date format
                807605
                sir :)

                I didn't get you exactly.

                oh k today is friday 7:00 how can I get date on next monday 7:00 and last monday 7:00???

                Can you please tell me that??

                Regards,
                Chintan
                • 5. Re: Regarding java.util.date / simple date format
                  807605
                  sir :)

                  I didn't get you exactly.

                  oh k today is friday 7:00 how can I get date on next
                  monday 7:00 and last monday 7:00???

                  Can you please tell me that??

                  Regards,
                  Chintan
                  YOu need a lookup map for 7 days in numerical terms.
                  Get the diff between today and that day
                  Add/subtract to today
                  • 6. Re: Regarding java.util.date / simple date format
                    807605
                    so basically there are no APIs available where I can get date object for next monday / previous monday and I have to find that out how to get that???

                    I was looking out for some straight forward API.
                    • 7. Re: Regarding java.util.date / simple date format
                      807605
                      There's not (to my knowledge) a single call you can make to obtain what you want.

                      However, it's not hard. Create a Calendar object, set its time to 7:00. If it's now in the past (use before/after and another Calendar object), add one day and you have the next 7:00.

                      Monday is similar, just set the day of week too, and if it's in the past, add a week rather than a day.

                      1st of a month is similar.

                      Write again if you run into trouble.