Results 1 to 5 of 5
  1. #1
    aliencc is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default Create new Calendar object???

    hi everyone,
    well here is my code:

    private static SimpleDateFormat formatter = new SimpleDateFormat("dd. mm. yyyy hh:mm:ss");
    public void print(Calendar begin){
    Calendar end= Calendar begin;
    end.add(Calendar.HOUR_OF_DAY,3);
    System.out.println("begin:" + formatter.format(begin.getTime()));
    System.out.println("end:" + formatter.format(begin.getTime()));
    }

    Well the output is begin and end are both the same, that mean after end.add, both begin and end were added.
    How can i creat a new Calendar object, that has 3hours more than the current Calendar i have, without changing the current Calendar?

    many thanks:)

  2. #2
    jomypgeorge is offline Member
    Join Date
    May 2010
    Posts
    90
    Rep Power
    0

    Default

    Calendar.getInstance();

    then u can call set() to set time

  3. #3
    aliencc is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    hmm the problem is i dont know the exactly time yet, so how can i call the set()
    methode?
    I wanna get a Calendar, that has 3 more hours than my input.

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Create the Calendar instance as suggested by jomypgeorge. Then pass it on to the print method. Make sure to assign it to another Calendar instance in the right way.

    The add method would do the work for you. Make sure to print the begin time before adding 3 hours to your Calendar. Currently the way you are printing the times, would end up showing the same time.

    Then, use the date formatter in the right way, what I am saying is, 'mm' stands for minutes and 'MM' stands for month. Don't get confused there.

    Hope that would help,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    aliencc is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    If I only want to print the time it will really help, but i need both Calendar for later use(for method check_avaiable(Calendar begin,Calendar ende)).

    well i just asked someone and founded out the solution:

    Calendar end = Calendar.getInstance();
    end.set(begin.get(Calendar.YEAR),....., begin.get(Calendar.HOUR_OF_DAY)+3,......);

    many thanks for all your helps:)

Similar Threads

  1. Replies: 2
    Last Post: 06-22-2010, 04:29 AM
  2. create object
    By paul21 in forum New To Java
    Replies: 4
    Last Post: 03-07-2010, 07:14 PM
  3. Create Calendar with Java
    By neoseeker191 in forum New To Java
    Replies: 4
    Last Post: 10-17-2008, 05:41 AM
  4. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM
  5. calendar object in preparedStatement
    By Heather in forum SWT / JFace
    Replies: 3
    Last Post: 06-30-2007, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •