1 6 7 package org.contineo.core; 8 9 import java.util.Date ; 10 import java.text.SimpleDateFormat ; 11 import java.text.ParsePosition ; 12 import org.contineo.core.LocaleBean; 13 14 20 public class DateBean extends Date { 21 22 private static final long serialVersionUID = 1L; 23 24 28 public static String toCompactString() { 29 SimpleDateFormat targetFormat = new SimpleDateFormat (); 30 targetFormat.applyPattern("yyyyMMdd"); 31 String result = targetFormat.format(new DateBean()); 32 33 return result; 34 } 35 36 42 public static String toCompactString(String date, String lang) { 43 if (date != null && !date.equals("")) 44 return convertDate(new LocaleBean().getDateFormat(lang), "yyyyMMdd", date); 45 else 46 return ""; 47 } 48 49 55 public static String toLocaleString(String date, String lang) { 56 if (date != null && !date.equals("")) 57 return convertDate("yyyyMMdd", new LocaleBean().getDateFormat(lang), date); 58 else 59 return ""; 60 } 61 62 69 public static String convertDate(String formatIn, String formatOut, String dateIn) 70 { 71 try { 72 return (new SimpleDateFormat (formatOut)).format((new SimpleDateFormat (formatIn).parse(dateIn, new ParsePosition (0)))); 73 } catch (Exception ex) { 74 return null; 75 } 76 } 77 } | Popular Tags |