Solved

date -1

Posted on 2013-11-29
2
254 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
2 Comments
 
LVL 26

Accepted Solution

by:
dpearson earned 425 total points
Comment Utility
// 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
Comment Utility
Thanks. Works like a charm!
Happy Thanksgiving Doug :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now