Java Date Format As formatDateTd(Object obj)

Here you can find the source of formatDateTd(Object obj)

Description

format Date Td

License

Apache License

Declaration

public static String formatDateTd(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

public class Main {
    public static String formatDateTd(Object obj) {
        String out = "<td style='text-align:center'>";
        String strDate = formatDate(obj);
        if (strDate.length() == 0) {
            // if you don't put a "non-breaking space" in an empty td/cell, 
            // the cell's border doesn't show !
            out += "&nbsp;";
        } else {//  ww  w . ja v a2  s  .co m
            out += strDate;
        }
        out += "</td>";
        return out;
    }

    public static String formatDate(Object obj) {
        if (obj == null) {
            return "";
        }
        try {
            java.util.Date dateval = (java.util.Date) obj;
            SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy");
            dateformat.setLenient(false);
            return dateformat.format(dateval);
        } catch (Exception e) {
            return "bad date in FormatUtils.formatDate: " + obj.toString() + " error: " + e.getMessage();
        }
    }
}

Related

  1. formatDatemhs(java.util.Date date)
  2. formatDateMonth(Date d)
  3. formatDateRfc822(Date date)
  4. formatDateStamp(final Date date)
  5. formatDateSwedish(Date date)
  6. formatDateToday()
  7. formatDateToDefault(Date date)
  8. formatDateToMD(Date date)
  9. formatDateToMinutes(Date date)