Today(YES), Yesterday(NO!), date related problem.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Today(YES), Yesterday(NO!), date related problem.

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Finland
    Posts
    10

    Today(YES), Yesterday(NO!), date related problem.

    If only someone could help

    All code(s) below gives me a current date,
    but I also need to get tomorrows and yesterdays dates.

    I think I canīt use simpledateformat because I need to import import java.sql.*;

    So if anyone can tell me how to modify some of the codes below, It would be great. All codes gives me date 2004-08-03 but how can I get forexample 2004-08-02 or 2004-08-04??


    these are what I have try to use without success

    1.
    Code:
    java.sql.Date date = 
            new java.sql.Date((new GregorianCalendar()).getTime().getTime()); 
        jTextField2.setText(""+date);
    2.
    Code:
    Calendar cal = GregorianCalendar.getInstance();
          DateFormat fmt = DateFormat.getInstance();
          String buf = fmt.format(cal.getTime());
          
             
           jTextField2.setText(""+buf);
    3.
    Code:
     java.util.Date today =
    new java.util.Date();
    java.sql.Date sqlToday =
    new java.sql.Date(today.getTime()+1);
    jTextField2.setText(""+sqlToday);
    Last edited by hiisikukko; 08-03-2004 at 07:44 AM.

  2. #2
    Join Date
    Jun 2004
    Posts
    199
    use the roll method of Calendar.

    calendar.roll(Calendar.DAY_OF_YEAR, -1);
    calendar.roll(Calendar.DAY_OF_YEAR, +1);

    Make sure to test with Jan 1 and Dec 31.

  3. #3
    Join Date
    May 2004
    Location
    Durham, UK
    Posts
    174

  4. #4
    Join Date
    Aug 2004
    Posts
    46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center