date -1

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.
royjaydAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
dpearsonConnect With a Mentor Commented:
// 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
 
royjaydAuthor Commented:
Thanks. Works like a charm!
Happy Thanksgiving Doug :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.