Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 22nd, 2007, 01:28 PM
Registered User
Join Date: Oct 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Needs to get previous date from the given date


I have a requirement to get the previous day for a given date. Please find the code below. It is giving previous day of the current date but i need the previous day of the given date.

Kindly help in this,

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
         GregorianCalendar gc = new GregorianCalendar();
         }catch(ParseException e){
         Date d = gc.getTime();

Expected output : 21-JAN-2007
Resultant output : current date - 1 i.e suppose today is 22nd April 2007, then it is giving 21-Apr-2007.

Reply With Quote
  #2 (permalink)  
Old April 23rd, 2007, 05:25 AM
Registered User
Join Date: Feb 2007
Location: , , Armenia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Balla,
I try the following piece of code:

           GregorianCalendar gc = new GregorianCalendar();
           gc.setGregorianChange(new Date("22-Jan-2007"));
           Date d = new Date();


The number 86400000 in code above is 24 hours in milliseconds.


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Previous Date in vb.net kostaskir VB How-To 1 August 31st, 2007 09:21 AM
selecting date and previous dates harpua MySQL 0 April 5th, 2007 08:25 PM
How to get previous date? rupen Javascript How-To 1 June 26th, 2006 10:57 PM
DTS Import ( Date string to Date field) gfowajuh SQL Server 2000 1 September 30th, 2003 06:28 AM
Convert String Date to Date for a SQL Query tdaustin Classic ASP Basics 4 July 7th, 2003 06:01 PM

All times are GMT -4. The time now is 04:11 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.