Java Date to String date2Str(Calendar c, String format)

Here you can find the source of date2Str(Calendar c, String format)

Description

date Str

License

Apache License

Declaration

public static String date2Str(Calendar c, String format) 

Method Source Code


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

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    private static final String FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String date2Str(Calendar c) {// yyyy-MM-dd HH:mm:ss
        return date2Str(c, null);
    }/*from   w  ww  . j  a  v a 2  s . c o m*/

    public static String date2Str(Calendar c, String format) {
        if (c == null) {
            return null;
        }
        return date2Str(c.getTime(), format);
    }

    public static String date2Str(Date d) {// yyyy-MM-dd HH:mm:ss
        return date2Str(d, null);
    }

    public static String date2Str(Date d, String format) {// yyyy-MM-dd HH:mm:ss
        if (d == null) {
            return null;
        }
        if (format == null || format.length() == 0) {
            format = FORMAT;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String s = sdf.format(d);
        return s;
    }
}

Related

  1. ConvertToString(Date date, String format)
  2. convertToString(Date date, String style)
  3. convertToString(java.util.Date date)
  4. convertToString(String format, Date date)
  5. date2str(Calendar c)
  6. date2Str(Date aDate)
  7. date2Str(Date date)
  8. Date2Str(Date date)
  9. date2Str(Date date)