Results 1 to 5 of 5
Thread: Create new Calendar object???
- 01-17-2011, 12:42 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
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:)
- 01-17-2011, 12:51 PM #2
Member
- Join Date
- May 2010
- Posts
- 90
- Rep Power
- 0
Calendar.getInstance();
then u can call set() to set time
- 01-17-2011, 12:54 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
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.
- 01-17-2011, 01:07 PM #4
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,
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-17-2011, 01:19 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 8
- Rep Power
- 0
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
-
Create object of unknown class, based on existing object
By Zack in forum New To JavaReplies: 2Last Post: 06-22-2010, 04:29 AM -
create object
By paul21 in forum New To JavaReplies: 4Last Post: 03-07-2010, 07:14 PM -
Create Calendar with Java
By neoseeker191 in forum New To JavaReplies: 4Last Post: 10-17-2008, 05:41 AM -
Creating a Gregorian Calendar using a Date object gives date - 1
By prachi_goliwadekar in forum New To JavaReplies: 1Last Post: 05-08-2008, 08:32 PM -
calendar object in preparedStatement
By Heather in forum SWT / JFaceReplies: 3Last Post: 06-30-2007, 02:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks