Help from Date klassen

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • malik123
    New Member
    • Apr 2007
    • 5

    Help from Date klassen

    Hello!
    I can convert from the given date,month and year to a day of year with the following code.

    GregorianCalend ar cal = (GregorianCalen dar)Calendar.ge tInstance();
    cal.set(1996,0, 1);
    System.out.prin tln(cal.get(cal .DAY_OF_YEAR));
    Answer : 1

    My question is now i want to do opposite for eksempel i want to convert from the given year(1996) and a day of year(256) to date. How i can do that?
    I need help .
    Malik
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by malik123
    Hello!
    I can convert from the given date,month and year to a day of year with the following code.

    GregorianCalend ar cal = (GregorianCalen dar)Calendar.ge tInstance();
    cal.set(1996,0, 1);
    System.out.prin tln(cal.get(cal .DAY_OF_YEAR));
    Answer : 1

    My question is now i want to do opposite for eksempel i want to convert from the given year(1996) and a day of year(256) to date. How i can do that?
    I need help .
    Malik
    Create a new Calendar. Set it's Date to 1 January 1996. Add 256 to it's date field and you have the date.

    Comment

    • malik123
      New Member
      • Apr 2007
      • 5

      #3
      Originally posted by r035198x
      Create a new Calendar. Set it's Date to 1 January 1996. Add 256 to it's date field and you have the date.

      Problem:
      I have just year(1996) and a day of year(256).I want to convert this into a date.I donot have month and date,that i am trying now. How i can do that?
      I am very thankful to you.
      malik123

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by malik123
        Problem:
        I have just year(1996) and a day of year(256).I want to convert this into a date.I donot have month and date,that i am trying now. How i can do that?
        I am very thankful to you.
        malik123
        Do you know how to set the Date field of a gc to 1 January 1996?

        Comment

        • malik123
          New Member
          • Apr 2007
          • 5

          #5
          Originally posted by r035198x
          Do you know how to set the Date field of a gc to 1 January 1996?
          I didnot understand but you mean

          GregorianCalend ar cal = (GregorianCalen dar)Calendar.ge tInstance();
          cal.set(1996,0, 1);

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by malik123
            I didnot understand but you mean

            GregorianCalend ar cal = (GregorianCalen dar)Calendar.ge tInstance();
            cal.set(1996,0, 1);
            Isn't it supposed to be

            Code:
             GregorianCalendar gc = new GregorianCalendar(); 
            gc.setTime(Date.valueOf("1996-01-01"));
            Check the docs for java.sql.Date and for GregorianCalend ar.

            then you can do gc.add(Gregoria nCalendar.DAY, 256);

            Comment

            • malik123
              New Member
              • Apr 2007
              • 5

              #7
              I have tried but not found the correct result.

              I tried to explain my problem once again. I have just two inputs Year and Day of year for example we have year "2007" and day of year "39".

              From these two inputs i need following output.
              I want to get the output in date,month and year which is "8 Februar 2007".How i can do that.
              I am very thankful to you.
              malik123

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by malik123
                I have tried but not found the correct result.

                I tried to explain my problem once again. I have just two inputs Year and Day of year for example we have year "2007" and day of year "39".

                From these two inputs i need following output.
                I want to get the output in date,month and year which is "8 Februar 2007".How i can do that.
                I am very thankful to you.
                malik123
                Have you been reading what I've been posting? What happened when you tried it?

                Comment

                • malik123
                  New Member
                  • Apr 2007
                  • 5

                  #9
                  I have found it.
                  The exact code is

                  int å=2007;
                  int d=39;
                  GregorianCalend ar cal = (GregorianCalen dar)Calendar.ge tInstance();
                  cal.set(å,0,1);
                  cal.set(Calenda r.DAY_OF_YEAR,d );

                  System.Out.prin tln( (cal.get(cal.DA TE))+"-"+(cal.get(cal. MONTH)+1)+"-"+å);

                  Result is : 8-02-2007

                  I have done it.Thanks for helping me.
                  malik123

                  Comment

                  Working...