Solved

date -1

Posted on 2013-11-29
2
278 Views
Last Modified: 2013-11-29
hi guys

I have
String date as = "2013-11-29"

Any idea how i can get date - 1 ?
I am expecting date to be 2013-11-28

thanks.
0
Comment
Question by:royjayd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Accepted Solution

by:
dpearson earned 425 total points
ID: 39685788
// Parse the string into a Date object
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
            Date d = fmt.parse(date);

            // Subtract one day
            Calendar c = Calendar.getInstance() ;
            c.setTime(d) ;
            c.add(Calendar.DAY_OF_YEAR, -1);

            // Convert it back to a string
            String yesterday = fmt.format(c.getTime()) ;

Doug
0
 

Author Closing Comment

by:royjayd
ID: 39685859
Thanks. Works like a charm!
Happy Thanksgiving Doug :-)
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

623 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