Android Date Format format(Date date, String pattern)

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

Description

format

License

Open Source License

Declaration

public static String format(Date date, 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 a  va 2  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. toString(Date value, String format)
  2. toStringFR(Date date)
  3. toStringUS(Date date)
  4. toTimeString(Date value)
  5. format(Date date)
  6. formatData(Date date)
  7. formatDate(final Date date)
  8. getStringFromDate(Date date, String format)
  9. getFormatTomorrow(String format)