Java Timestamp Format formatTime(Date aTs_Datetime)

Here you can find the source of formatTime(Date aTs_Datetime)

Description

format Time

License

Apache License

Declaration

public static String formatTime(Date aTs_Datetime) 

Method Source Code


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

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

import java.util.Date;

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

    public static String formatTime(Date aTs_Datetime) {
        return format(aTs_Datetime, TIME_PATTERN_DEFAULT);
    }/* w ww .j  av a  2  s.  c  o  m*/

    /**
     * @param aTs_Datetime
     * @param as_Format
     * @return
     */
    public static String formatTime(Date aTs_Datetime, String as_Format) {
        if (aTs_Datetime == null || as_Format == null)
            return null;
        SimpleDateFormat dateFromat = new SimpleDateFormat();
        dateFromat.applyPattern(as_Format);

        return dateFromat.format(aTs_Datetime);
    }

    public static String format(Date aTs_Datetime) {
        return format(aTs_Datetime, DATE_PATTERN_DEFAULT);
    }

    public static String format(Date aTs_Datetime, String as_Pattern) {
        if (aTs_Datetime == null || as_Pattern == null)
            return null;
        SimpleDateFormat dateFromat = new SimpleDateFormat();
        dateFromat.applyPattern(as_Pattern);

        return dateFromat.format(aTs_Datetime);
    }

    /**
     * @param aTs_Datetime
     * @param as_Pattern
     * @return
     */
    public static String format(Timestamp aTs_Datetime, String as_Pattern) {
        if (aTs_Datetime == null || as_Pattern == null)
            return null;
        SimpleDateFormat dateFromat = new SimpleDateFormat();
        dateFromat.applyPattern(as_Pattern);

        return dateFromat.format(aTs_Datetime);
    }
}

Related

  1. formatShortDateTime(Timestamp time)
  2. formatStatement(PreparedStatement statement, List values)
  3. formatString(Timestamp da)
  4. formatStringToTimeStamp(String s)
  5. formattedDateTime(long timestamp)
  6. formatTime(Date date)
  7. formatTime(Timestamp time, boolean onlyTime)
  8. formatTime(Timestamp ts, Locale locale)
  9. formatTimeFromTimestamp(long ts, String fmt)

  10. HOME | Copyright © www.java2s.com 2016