-1

In Java, What can I use to convert the string "27/Jun/1991" to a date or timestamp?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179

3 Answers3

2

try this

SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy", Locale.ENGLISH);
Date date = sdf.parse("27/Jun/1991");
System.out.println(date);

output

Thu Jun 27 00:00:00 EEST 1991
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
  • Hi, output is: java.text.ParseException: Unparseable date: "27/Jun/1991" at java.text.DateFormat.parse(DateFormat.java:357) at svn_example1.SVN_Example1.main(SVN_Example1.java:661 i'm using jdk 1.7 – Khúc Củi May 22 '13 at 04:47
  • Well, I tested my code before posting, seems like you are running not my code – Evgeniy Dorofeev May 22 '13 at 04:56
  • Thanks for answer, SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy", Locale.ENGLISH); Locale.ENGLISH is important – Khúc Củi May 31 '13 at 10:04
0
SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy");  
     Date date=null;;
    try {
        date = formatter.parse("27/Jun/1991");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  
     System.out.println("Date::" +date);  
}
prvn
  • 916
  • 5
  • 5
0

Try this

    DateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy");
    Date d = null;
    try {
        d = formatter.parse("27/Jun/1991");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(d);
roger_that
  • 9,493
  • 18
  • 66
  • 102