Solved

date -1

Posted on 2013-11-29
2
272 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 27

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

734 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