Solved

date -1

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
even odd program using while loop 3 72
jdbc error in jsp application 20 71
Given a github repo find email address of all collaborators in that repo 1 29
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

685 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