Java Date to String date2String2(Date date)

Here you can find the source of date2String2(Date date)

Description

date String

License

Apache License

Declaration

public static String date2String2(Date date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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 String dateFormat7 = "HHmm";
    private static final Map<String, DateFormat> DFS = new HashMap<String, DateFormat>();

    public static String date2String2(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat7);
        String dateString = formatter.format(date);
        return dateString;
    }// w w w  .jav  a 2s  .  c  o m

    public static String format(Date date, String pattern) {
        if (date == null) {
            return null;
        }
        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. date2String(Date value)
  2. date2String(java.util.Date date, String format)
  3. date2String(java.util.Date date, String pattern)
  4. date2String(String formater, Date aDate)
  5. date2String(String pattern, Date date)
  6. date2StringISO(Date date)
  7. date2StringMD(Date date)
  8. date2StringPattern(Date value, String pattern)
  9. Date2StringSec(Date date)