Java SQL Time Format formatDate(String Format)

Here you can find the source of formatDate(String Format)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(String Format) 

Method Source Code


//package com.java2s;
import java.text.*;
import java.util.*;

public class Main {

    public static String formatDate(String Format) {
        java.util.Date d = Calendar.getInstance().getTime();
        try {//from w w w  . j a v  a 2  s  .  co m
            SimpleDateFormat f = new SimpleDateFormat(Format);
            return f.format(d);
        } catch (Exception e) {
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); // :iii
            return f.format(d);
        }
    }

    public static String formatDate(Date date) {
        String dateformat = "yyyy-MM-dd HH:mm";
        return formatDate(date, dateformat);

    }

    public static String formatDate(Date date, String dateformat) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
        return sdf.format(date);

    }

    public String getTime() {
        java.sql.Time ent = new java.sql.Time(System.currentTimeMillis());
        return ent.toString();
    }
}

Related

  1. formatCharDateYMD(String str)
  2. formatCharDateYMDHMS(String str)
  3. formatDateWithSlashes(java.sql.Date date)
  4. formatDateYM(Date date, String datePtn)
  5. formatDateYMD(String str, String datePtn)
  6. formatDefaultValue(Object o)