-1

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

Michael Petrotta
  • 58,479
  • 27
  • 141
  • 176

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
  • 262,936
  • 84
  • 758
  • 1,028
Evgeniy Dorofeev
  • 129,181
  • 28
  • 195
  • 266
  • 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
  • 918
  • 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,063
  • 18
  • 58
  • 96