Java Timestamp Field getDateString(Timestamp time, String pattern)

Here you can find the source of getDateString(Timestamp time, String pattern)

Description

get Date String

License

Apache License

Declaration

public static String getDateString(Timestamp time, 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 PATTERN_CLASSICAL = "yyyy-MM-dd HH:mm:ss";

    public static String getDateString(String pattern) {
        Timestamp time = getSysDate();
        DateFormat dfmt = new SimpleDateFormat(pattern);
        java.util.Date date = time;
        return dfmt.format(date);
    }/*from   w  ww  .  ja v  a 2  s  .co m*/

    public static String getDateString(Timestamp time, String pattern) {
        DateFormat dfmt = new SimpleDateFormat(pattern);
        Date date = time;
        return date != null ? dfmt.format(date) : "";
    }

    public static String getDateString(Date date, String pattern) {
        SimpleDateFormat sdfmt = new SimpleDateFormat(pattern);
        return date != null ? sdfmt.format(date) : "";
    }

    public static Timestamp getSysDate() {
        return new Timestamp(System.currentTimeMillis());
    }

    public static String format(Date date) {
        return format(date, PATTERN_CLASSICAL);
    }

    public static String format(Timestamp date) {
        return format(date, PATTERN_CLASSICAL);
    }

    public static String format(Date date, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }
}

Related

  1. getDateString(java.sql.Timestamp ts)
  2. getDateTime(Timestamp argRenDt)
  3. getDateTime(Timestamp timestamp)
  4. getDateTimeFromSqlTimestamp(Timestamp timestamp)
  5. getDateTimeFromTimeStamp(Timestamp timestamp)