Java Timestamp getTimeStr(Timestamp tsp)

Here you can find the source of getTimeStr(Timestamp tsp)

Description

get Time Str

License

Open Source License

Declaration

public static String getTimeStr(Timestamp tsp) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

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

public class Main {

    public static String getTimeStr(Timestamp tsp) {
        if (tsp == null) {
            return "";
        }//from   w w  w.  j  ava  2 s. com
        return dateToStr(new Date(tsp.getTime()));
    }

    public static String dateToStr(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(date).trim();
    }

    /**
     * <p>
     * Formats a date/time into a specific pattern.
     * </p>
     * 
     * @param date
     *            the date to format
     * @param pattern
     *            the pattern to use to format the date
     * @return the formatted date
     */
    public static String format(Date date, String pattern) {
        return format(date, pattern, null);
    }

    /**
     * <p>
     * Formats a date/time into a specific pattern in a time zone and locale.
     * </p>
     * 
     * @param date
     *            the date to format
     * @param pattern
     *            the pattern to use to format the date
     * @param locale
     *            the locale to use, may be <code>null</code>
     * @return the formatted date
     */
    public static String format(Date date, String pattern, Locale locale) {
        if (locale == null) {
            locale = Locale.getDefault();
        }
        SimpleDateFormat df = new SimpleDateFormat(pattern, locale);
        return df.format(date);
    }

    /**
     * <p>
     * Formats a date/time into a specific pattern.
     * </p>
     * 
     * @param millis
     *            the date to format expressed in milliseconds
     * @param pattern
     *            the pattern to use to format the date
     * @return the formatted date
     */
    public static String format(long millis, String pattern) {
        return format(new Date(millis), pattern, null);
    }

    /**
     * <p>
     * Formats a date/time into a specific pattern in a time zone and locale.
     * </p>
     * 
     * @param millis
     *            the date to format expressed in milliseconds
     * @param pattern
     *            the pattern to use to format the date
     * @param locale
     *            the locale to use, may be <code>null</code>
     * @return the formatted date
     */
    public static String format(long millis, String pattern, Locale locale) {
        return format(new Date(millis), pattern, locale);
    }
}

Related

  1. getTimeFromTimestamp( java.sql.Timestamp tsZeitpunkt)
  2. getTimeNanoSec(Timestamp t)
  3. getTimeNextDay(Timestamp date)
  4. getTimeNextMonthFirstSec(Timestamp sysDate)
  5. getTimePassedSince(Timestamp timestamp)
  6. getTimeString(java.sql.Timestamp ts)
  7. getTimeString(Timestamp timestamp)
  8. getTodayTimestamp()
  9. getUtilDate(java.sql.Timestamp time)