Java Timestamp Format formatDateTime(Timestamp t, String pattern)

Here you can find the source of formatDateTime(Timestamp t, String pattern)

Description

format Date Time

License

Apache License

Declaration

public static String formatDateTime(Timestamp t, String pattern) 

Method Source Code


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

import java.sql.Timestamp;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String STANDARD_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public final static String STANDARD_DATE_PATTERN = "yyyy-MM-dd";

    public static String formatDateTime(Timestamp t, String pattern) {
        return formatDate(new Date(t.getTime()), STANDARD_DATETIME_PATTERN);
    }/*from   ww  w.j  a va  2  s  .com*/

    public static String formatDateTime(Date date) {
        return formatDate(date, STANDARD_DATETIME_PATTERN);
    }

    public static String formatDate(Timestamp t) {
        return formatDate(new Date(t.getTime()));
    }

    public static String formatDate(Timestamp t, String pattern) {
        return formatDate(new Date(t.getTime()), STANDARD_DATE_PATTERN);
    }

    public static String formatDate(Date date) {
        return formatDate(date, STANDARD_DATE_PATTERN);
    }

    public static String formatDate(Date date, String pattern) {
        if (date == null)
            return null;
        DateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }
}

Related

  1. formatDateHour(Date date)
  2. formatDateTime(Date date)
  3. formatDateTime(java.sql.Timestamp ts)
  4. formatDateTime(long ms)
  5. formatDateTime(String dTime)
  6. formatDateTimeStamp(final Date date)
  7. formatDateToTimestamp(String string)
  8. formatDateToUnixTimestamp(Date date)
  9. formatDateWithCinderellaTime(Date date)