-1

How to convert int type of date ArrayList to date format like 24/05/2014.?in java

getLoyalityExpiryDate() this method returns arraylist ,from this type of int arralist dates to type of String arraylist dates transformation I need .please help me.

example:20140524(arrayList) to 24/05/2014(Arraylist)?in java

Thanks in advance.

maddy
  • 1
  • 3
  • What is a date arraylist? – Ray Toal Jun 10 '14 at 04:24
  • I have to convert 20140524 to 24/05/2014 format but dynamically . Based on customer number transaction dates can be many. – maddy Jun 10 '14 at 04:27
  • Those look like strings. Where are the arraylists? – Ray Toal Jun 10 '14 at 04:27
  • yeah int to String only..... I have taken Array list bcz customer may have many transaction dates the above mentioned format is required one. – maddy Jun 10 '14 at 04:30
  • But I don't see ints either. Do you just need to transform the _string_ `"20140524"` into the _string_ `"24/05/2014"`? – Ray Toal Jun 10 '14 at 04:33
  • 20140524 it is type of int .... – maddy Jun 10 '14 at 04:37
  • getLoyalityExpiryDate(); returns arraylist .... from this type of int arraylist to String type of array list . – maddy Jun 10 '14 at 04:50
  • 1
    Assuming all ints are exactly 6 digits: `List result = new ArrayList(); for (int d: getLoyaltyExpiryDate()) {String s = Integer.toString(d); result.add(s.substring(6) + "/" + s.substring(4,6) + "/" + s.substring(0,4));}` Better would be to parse and format the dates using a `SimpleDateFormat`. – Ray Toal Jun 10 '14 at 06:55

1 Answers1

0

Split the string to the corresponding day month and year.

String year = expDate1.substring(0, 4);

String month = expDate1.substring(4, 6) ;

String day = expDate1.substring(6,8) ;

Date date= new Date(year, month, date);
Dileep
  • 5,362
  • 3
  • 22
  • 38