In Java, What can I use to convert the string "27/Jun/1991" to a date or timestamp?
Asked
Active
Viewed 82 times
-1
-
1What language/framework? – Michael Petrotta May 22 '13 at 04:33
-
Thanks for answer, i'm using java – Khúc Củi May 22 '13 at 04:37
-
1Simply Use [SimpleDateFormat](http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html) – hanut May 22 '13 at 04:39
-
@Luv, please take care with your edits. Code formatting is meant to be used for code, not merely to highlight portions of text. – Michael Petrotta May 22 '13 at 04:42
-
Possible duplicate of [Java string to date conversion](http://stackoverflow.com/questions/4216745/java-string-to-date-conversion) – devnull May 22 '13 at 04:53
-
@MichaelPetrotta I will take care of it. Thanks for your Advice **`:)`** – Prahalad Gaggar May 22 '13 at 05:45
3 Answers
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