How to convert String to Date

Discussion in 'Java' started by javaeecoding, Sep 6, 2008.

  1. javaeecoding

    javaeecoding

    Joined:
    Sep 6, 2008
    Messages:
    1
    The codes below show you how to convert String to Date in Java.

    The copyright of the codes belongs to javaeecoding.com

    HTML:
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    import java.util.Date; 
    
    public class StringToDateConverter 
    {    
        public static void main(String[] args)    
        {        
            DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");         
            
           try        
            {            
                 // to convert String to Date in format yyyy-MM-dd            
                 Date date1 = dateFormat1.parse("2008-08-09");
                 System.out.println("date1 = " + date1);        
            }         
            catch (ParseException ex)        
            {
                  ex.printStackTrace();        
             }    
        }
    }
     
    javaeecoding, Sep 6, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. h_ghanaty

    convert gregorian date to jalay date

    h_ghanaty, Nov 7, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    553
    Bret Mulvey [MS]
    Nov 9, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,367
    Michael Borgwardt
    May 30, 2004
  3. wgan
    Replies:
    7
    Views:
    616
    Roedy Green
    Jul 8, 2004
  4. deepak_kamath_n@yahoo.co.in

    Convert date recevied as String to date in local time zone

    deepak_kamath_n@yahoo.co.in, Apr 28, 2007, in forum: C++
    Replies:
    8
    Views:
    819
    Boris
    May 1, 2007
  5. davyb
    Replies:
    7
    Views:
    224
    Gregory Brown
    Nov 18, 2005
Loading...

Share This Page