help to show integer value in a time format - newbie

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mumbaimacro
    New Member
    • Sep 2006
    • 25

    help to show integer value in a time format - newbie

    dear all

    i am n a situation to display from a int value into Time format,
    is there any possiblity of using existing java util classes? or i need to rite my own class?
    kindly help me to get a sloution ,
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by mumbaimacro
    dear all

    i am n a situation to display from a int value into Time format,
    is there any possiblity of using existing java util classes? or i need to rite my own class?
    kindly help me to get a sloution ,
    Can you describe your problem more clearly.
    What should the output be if the program was given the following
    • 2
    • -1
    • 0
    • 1945
    • 1999876
    • Integer.MAX_VAL UE
    which are all valid integers?

    Comment

    • mumbaimacro
      New Member
      • Sep 2006
      • 25

      #3
      Originally posted by r035198x
      Can you describe your problem more clearly.
      What should the output be if the program was given the following
      • 2
      • -1
      • 0
      • 1945
      • 1999876
      • Integer.MAX_VAL UE
      which are all valid integers?
      Ans:

      the valid input in the above list is --> 1945 & the o/p will be like this 7.45 pm


      hi ,

      the integer value size is 4, ( which i stored in table as Time)
      for example

      if time is 1500 in table >>
      then i have to show , something like this format 3.00 pm in screen

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by mumbaimacro
        Ans:

        the valid input in the above list is --> 1945 & the o/p will be like this 7.45 pm


        hi ,

        the integer value size is 4, ( which i stored in table as Time)
        for example

        if time is 1500 in table >>
        then i have to show , something like this format 3.00 pm in screen
        Well now don't you think that is a better description of the problem now?
        You can write your own method or use the GregorianCalend ar class.
        Better do this in steps.
        First determine whether the input is valid or not (must be positive and must contain 4 digits).
        Then split the digits by half into hours and minutes. You can then either set those into a gc to get the am or pm or use a if else to do it yourself manually.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by mumbaimacro
          Ans:

          the valid input in the above list is --> 1945 & the o/p will be like this 7.45 pm
          But then the value '2' should be valid as well: two minutes past midnight.
          For an int value x, x/100 represents the hours and x%100 represents the
          minutes.

          kind regards,

          Jos

          Comment

          • mumbaimacro
            New Member
            • Sep 2006
            • 25

            #6
            Originally posted by r035198x
            Well now don't you think that is a better description of the problem now?
            You can write your own method or use the GregorianCalend ar class.
            Better do this in steps.
            First determine whether the input is valid or not (must be positive and must contain 4 digits).
            Then split the digits by half into hours and minutes. You can then either set those into a gc to get the am or pm or use a if else to do it yourself manually.

            thanks for the suggestion sir, i will write a method to do this.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by mumbaimacro
              thanks for the suggestion sir, i will write a method to do this.
              Have a look at Jos' post above and think about it as well.
              It's you who comes up with the rules but make sure your rules are workable. If you restrict the numbers to 4 digits will your program be easy to work with?

              Comment

              • mumbaimacro
                New Member
                • Sep 2006
                • 25

                #8
                Originally posted by r035198x
                Have a look at Jos' post above and think about it as well.
                It's you who comes up with the rules but make sure your rules are workable. If you restrict the numbers to 4 digits will your program be easy to work with?

                u r correct, if dere s a requirement to include seconds then the size will be 6

                in that case for eg : 194512 and i need to format 19:45:12 (hh:mm:ss)

                then i have to frame the method....

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by r035198x
                  Have a look at Jos' post above and think about it as well.
                  It's you who comes up with the rules but make sure your rules are workable. If you restrict the numbers to 4 digits will your program be easy to work with?
                  I'd say four digits or less, more exact the number must be < 2400 for starters.

                  kind regards,

                  Jos

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by mumbaimacro
                    u r correct, if dere s a requirement to include seconds then the size will be 6

                    in that case for eg : 194512 and i need to format 19:45:12 (hh:mm:ss)

                    then i have to frame the method....
                    There we go again ...

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by mumbaimacro
                      u r correct, if dere s a requirement to include seconds then the size will be 6

                      in that case for eg : 194512 and i need to format 19:45:12 (hh:mm:ss)

                      then i have to frame the method....
                      I'd say forget about the thing entirely; store date/time values as date/time types
                      and use a SimpleDateForma tter for the display of it all. That way you don't have
                      to write your own classes and you can handle everything you ever have to handle.

                      kind regards,

                      Jos

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by JosAH
                        I'd say forget about the thing entirely; store date/time values as date/time types
                        and use a SimpleDateForma tter for the display of it all. That way you don't have
                        to write your own classes and you can handle everything you ever have to handle.

                        kind regards,

                        Jos
                        I hope no new information about the problem emerges again ...

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by r035198x
                          I hope no new information about the problem emerges again ...
                          I suspect the OP to be a customer; they always do that and they're driving me crazy ;-)

                          me: So you're absolutely sure that what I wrote down are all your requirements?
                          customer: Yes.
                          me: Really absolutely positively sure? We can go through it one more time again.
                          customer: not needed, this is it; I'm sure.
                          me: Really, really, really sure?
                          customer: yes.
                          me: Ok fine, I'm glad we settled the entire issue.
                          customer: me too, I'm glad we can take the next step.
                          me: yup, see you next week then.
                          customer: yes, fine; oh, btw we decided that we want all the menus coloured green
                          and while I'm at it the application should automagically smell that we want the reports
                          to be produced even if we haven't supplied all data yet and we want the application
                          to be able to start Solitaire as well, but only for my account. And my nephew told
                          me that Java sucks so we don't want that; we do want J2EE technology instead
                          because we're a modern company. And we want Oracle as well instead of DB2.
                          On a floppy disk please so I can take it home with me for security reasons.

                          <curtain/>

                          kind regards,

                          Jos ;-)

                          Comment

                          • mumbaimacro
                            New Member
                            • Sep 2006
                            • 25

                            #14
                            Originally posted by JosAH
                            I suspect the OP to be a customer; they always do that and they're driving me crazy ;-)

                            me: So you're absolutely sure that what I wrote down are all your requirements?
                            customer: Yes.
                            me: Really absolutely positively sure? We can go through it one more time again.
                            customer: not needed, this is it; I'm sure.
                            me: Really, really, really sure?
                            customer: yes.
                            me: Ok fine, I'm glad we settled the entire issue.
                            customer: me too, I'm glad we can take the next step.
                            me: yup, see you next week then.
                            customer: yes, fine; oh, btw we decided that we want all the menus coloured green
                            and while I'm at it the application should automagically smell that we want the reports
                            to be produced even if we haven't supplied all data yet and we want the application
                            to be able to start Solitaire as well, but only for my account. And my nephew told
                            me that Java sucks so we don't want that; we do want J2EE technology instead
                            because we're a modern company. And we want Oracle as well instead of DB2.
                            On a floppy disk please so I can take it home with me for security reasons.

                            <curtain/>

                            kind regards,

                            Jos ;-)

                            dear all

                            sorry for the late reply....as i cant change ma existing data type since its an production data...only thing writing own class..
                            Moreover i m a new bie , so slow to get the things...

                            thanks for replies

                            Comment

                            • JosAH
                              Recognized Expert MVP
                              • Mar 2007
                              • 11453

                              #15
                              Originally posted by mumbaimacro
                              dear all

                              sorry for the late reply....as i cant change ma existing data type since its an production data...only thing writing own class..
                              Moreover i m a new bie , so slow to get the things...

                              thanks for replies
                              Ok, so a date/time value is stored as an int. So far so good; What exactly is
                              stored in that int? The time of the day? Are seconds, milliseconds included?
                              We need to specify exactly what is in that int and how time is encoded as an
                              int value before we can start designing or even implementing fancy classes.

                              Right now we haven't even touched the specification/requirement stage which
                              has to be completed before we can even design something.

                              kind regards,

                              Jos

                              Comment

                              Working...