DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Threaded 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.

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links