Java Hour Format formatSqlDateTime(Date value)

Here you can find the source of formatSqlDateTime(Date value)

Description

format Sql Date Time

License

Open Source License

Declaration

public static String formatSqlDateTime(Date value) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

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

    public static String formatSqlDateTime(Date value) {
        return formatDate(value, PATTERN_SQL_DATETIME_FULL, null);
    }/*  w w w  .jav  a 2 s.co m*/

    /**
     * format the date with the given pattern.
     * 
     * @param value Date
     * @param pattern String the format pattern, for example,
     *            SimpleDate.PATTERN_US_DATE
     * @param tz TimeZone if null,will use the server's default timezone
     * @return String the formated string
     */
    public static String formatDate(Date value, String pattern, TimeZone tz) {

        if (value == null) {
            return "";
        }
        SimpleDateFormat formater = new SimpleDateFormat(pattern, Locale.US);
        if (tz != null) {
            formater.setTimeZone(tz);
        }
        return formater.format(value);
    }
}

Related

  1. formatShortDate(java.util.Date date)
  2. formatShortTime()
  3. formatSimpleTimeAndDateString(Date date)
  4. formatSingleFractionHours(Double updatedHours)
  5. formatSQL(Date date)
  6. formatSSLValid(Date validFrom, Date validTo)
  7. formatStringTime(String dateTime)
  8. formatStringTimeToLong(String timeLine)
  9. formatStrToDate(String strDate, int format)