[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to add 2 months to Timestamp?

Posted on 2007-08-08
4
Medium Priority
?
1,822 Views
Last Modified: 2013-11-05
add 2 months to Timestamp?
0
Comment
Question by:chaitu chaitu
  • 3
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 19653192
Calendar cal = Calendar.getInstance();
cal.setTime(ts);
cal.add(Calendar.MONTH, 2);
ts = new Timestamp(cal.getTime().getTime());
0
 
LVL 2

Expert Comment

by:tbeernot
ID: 19653374
GregorianCalendar lGregorianCalendar = new GregorianCalendar();
lGregorianCalendar.setTimeInMillis( ts.getTime() );
lGregorianCalendar.add(Calendar.MONTH, 2);
            
ts.setTime( lGregorianCalendar.getTimeInMillis() );
0
 
LVL 2

Expert Comment

by:tbeernot
ID: 19653376
hmm, objects answered while I had the question open
0
 
LVL 2

Expert Comment

by:tbeernot
ID: 19660018
Ehm, objects... Your solution IMHO has a flaw: it does not copy the nano seconds part of Timestamp. (Timestamp is milleseconds + nanoseconds), you create a new TS without copy the nano seconds part.

Because my approach reuses the original Timestamp, it does not have that problem.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question