Java Timestamp to String timestamp2String(Timestamp timestamp, String pattern)

Here you can find the source of timestamp2String(Timestamp timestamp, String pattern)

Description

timestamp String

License

Open Source License

Declaration

public static String timestamp2String(Timestamp timestamp, String pattern) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;

import java.text.SimpleDateFormat;

import java.util.Date;

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

    public static String timestamp2String(Timestamp timestamp, String pattern) {
        if (timestamp == null) {
            throw new java.lang.IllegalArgumentException("timestamp null illegal");
        }//from  ww w .ja va  2 s.  co  m
        if (pattern == null || pattern.equals("")) {
            pattern = PATTERN_STANDARD;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(new Date(timestamp.getTime()));
    }
}

Related

  1. timestamp2Str(Timestamp time, String format)
  2. timestamp2String(final java.sql.Timestamp value)
  3. timestamptoStr(Timestamp time)
  4. timeStampToString(final Timestamp timestamp, final String format)
  5. timestampToString(java.sql.Timestamp a_Timestamp, String aS_Format)
  6. timestampToString(long timestamp)