Java Date Now currentDate2String()

Here you can find the source of currentDate2String()

Description

current Date String

License

Open Source License

Declaration

public static String currentDate2String() 

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 currentDate2String() {
        return date2String(new Date());
    }/*from   w w  w  .j ava2s .  co m*/

    public static String date2String(Date date) {
        return date2String(date, "yyyy-MM-dd HH:mm:ss.SSS");
    }

    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. currentDate()
  2. currentDate(int dateStyle)
  3. currentDate(String format)
  4. currentDate(String format, Locale locale)
  5. currentDate(String format, String locale)
  6. currentDate2String()
  7. currentDate_DDMMYY()
  8. currentDateAsString()
  9. currentDatePath(String basePath)