1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* Parsing custom formatted date string into Date object using SimpleDateFormat This example shows how to parse string containing date and time in custom formats into Date object using Java SimpleDateFormat class. */ import java.util.Date; import java.text.ParseException; import java.text.SimpleDateFormat; public class ParsingCustomFormatDate { public static void main(String[] args) { //create object of SimpleDateFormat class with custom format SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy"); try { //parse string containing specified format into date object Date date = sdf.parse("31/12/06"); System.out.println(date); } catch(ParseException pe) { System.out.println("Parse Exception : " + pe); } } } |
Add Comment