Sunday, 4 May 2014

change date to Specified formats

public class changeDateFormatCO extends OAControllerImpl {
    public changeDateFormatCO() {
    }
    public void processRequest(OAPageContext pageContext,OAWebBean webBean) {
super.processRequest(pageContext,webBean);
Calendar cal=Calendar.getInstance();
Locale locale = new Locale("en", "US", "WIN"); 
String date=dateFormat(cal.getTime(),0,locale);
}
    public void processFormRequest(OAPageContext pageContext,OAWebBean webBean) {
super.processFormRequest(pageContext,webBean);
 }

public static String dateFormat(Date paramDate, int paramInt, Locale paramLocale)
  {
    String str = "";

    if (paramDate != null)
    {
      switch (paramInt) {
      case 0:
        SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat("yyyy/MM/dd", paramLocale);
        str = localSimpleDateFormat1.format(paramDate);
        break;
      case 1:
        SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat("HH:mm:ss", paramLocale);
        str = localSimpleDateFormat2.format(paramDate);
        break;
      case 2:
        SimpleDateFormat localSimpleDateFormat3 = new SimpleDateFormat("HH:mm", paramLocale);
        str = localSimpleDateFormat3.format(paramDate);
        break;
      case 3:
        SimpleDateFormat localSimpleDateFormat4 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", paramLocale);
        str = localSimpleDateFormat4.format(paramDate);
        break;
      case 4:
        SimpleDateFormat localSimpleDateFormat5 = new SimpleDateFormat("EEEEE, MMMMM dd yyyy", paramLocale);
        str = localSimpleDateFormat5.format(paramDate);
        break;
      case 5:
        SimpleDateFormat localSimpleDateFormat6 = new SimpleDateFormat("EEE, MMM dd", paramLocale);
        str = localSimpleDateFormat6.format(paramDate);
        break;
      case 6:
        SimpleDateFormat localSimpleDateFormat7 = new SimpleDateFormat("EEE", paramLocale);
        str = localSimpleDateFormat7.format(paramDate);
        break;
      case 7:
        SimpleDateFormat localSimpleDateFormat8 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS", paramLocale);
        str = localSimpleDateFormat8.format(paramDate);
        break;
      case 8:
        SimpleDateFormat localSimpleDateFormat9 = new SimpleDateFormat("EEEEE", paramLocale);
        str = localSimpleDateFormat9.format(paramDate);
      }

    }

    return str;
  }
}

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete