Java SQL Date Parse parseDate2(Date date, String pattern)

Here you can find the source of parseDate2(Date date, String pattern)

Description

parse Date

License

Apache License

Declaration

public static String parseDate2(Date date, 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 static final String DATE_PATTERN_DEFAULT = "yyyy-MM-dd";

    public static String parseDate2(Date date, String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        return df.format(date);
    }/*from w  w w . j a va 2 s. c  o m*/

    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. parseDate(String s)
  2. parseDate(String s)
  3. parseDate(String strDate)
  4. parseDate(String strFormat, String dateValue)
  5. parseDate(String value, String format)
  6. parseDateE(Date dt)
  7. parseDateString(String tmp, String format)
  8. parseDateYYMMddHHmm(java.util.Date date)
  9. parseDateYYMMddHHmmss1(Date date)