Java Date to String date2String(Date date)

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

Description

date String

License

Open Source License

Declaration

public static String date2String(Date date) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    public static final String DEFAULT_PATTERN = "yyyy-MM-dd";
    private static SimpleDateFormat formatter = new SimpleDateFormat(DEFAULT_PATTERN);

    public static String date2String(Date date) {
        return date2String(date, "yyyy-MM-dd HH:mm:ss.SSS");
    }/*from w w w  .j  a v  a 2s.c  om*/

    public static String date2String(Date date, String pattern) {
        if (date == null) {
            return null;
        }

        formatter.applyPattern(pattern);
        String d = formatter.format(date);
        formatter.applyPattern(DEFAULT_PATTERN);
        return d;
    }

    public static String date2String(Date date, String pattern, Locale locale) {
        if (date == null) {
            return null;
        }
        return (new SimpleDateFormat(pattern, locale)).format(date);
    }
}

Related

  1. date2string(Date date)
  2. date2String(Date date)
  3. date2String(Date date)
  4. date2String(Date date)
  5. date2String(Date date)
  6. date2string(Date date)
  7. date2String(Date date)
  8. date2String(Date date, DateFormat dateFormat)
  9. date2String(Date date, int _iType)