Android Timestamp Format format(Timestamp tt, String pattern)

Here you can find the source of format(Timestamp tt, String pattern)

Description

format

License

Open Source License

Declaration

public static String format(Timestamp tt, String pattern) 

Method Source Code

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

import java.sql.Timestamp;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.HashMap;
import java.util.Map;

public class Main {
    private static final Map<String, DateFormat> DFS = new HashMap<String, DateFormat>();

    public static String format(Date date, String pattern) {
        if (date == null) {
            return null;
        }/*w w w .  j  av  a2  s.c  o  m*/
        return getFormat(pattern).format(date);
    }

    public static String format(Timestamp tt, String pattern) {
        if (tt == null) {
            return null;
        }
        Date date = new Date(tt.getTime());
        return getFormat(pattern).format(date);
    }

    public static DateFormat getFormat(String pattern) {
        DateFormat format = DFS.get(pattern);
        if (format == null) {
            format = new SimpleDateFormat(pattern);
            DFS.put(pattern, format);
        }
        return format;
    }
}

Related

  1. formatDate(Timestamp value)
  2. formatDate(Timestamp value, String defaultFormat)
  3. formatDateTime(Timestamp value)
  4. formatDateTime(Timestamp value, String defaultFormat)