Parsing dates in Java?

I have dates in text format of the form dd-mmm-yy or d-mmm-y, where the months are the abbreviations in letters (for example, November 4-09 or 12-Dec-05, etc.)) I would like parse it to create a java.util.Date object.

Can this be achieved by using the java.text.DateFormat class? Or is there another easy way to do this?

+2
source share
5 answers

You may need to use SimpleDateFormat to parse custom formats. This article explains the formatting details.

"d-MMM-yyyy" corresponds to 4-Nov-2009
+4
source
+2

java.text.SimpleDateFormat. , .

1-2- d. 3- MMM. yy.

, :

String dateString = "4-Nov-09";
SimpleDateFormat sdf = new SimpleDateFormat("d-MMM-yy");
Date date = sdf.parse(dateString);
+1

, Locale. , - , .

+1
0
source

Source: https://habr.com/ru/post/1770397/


All Articles