Java yyyy formatDate(Calendar cal, String pattern)

Here you can find the source of formatDate(Calendar cal, String pattern)

Description

format Date

License

Apache License

Declaration

public static String formatDate(Calendar cal, String pattern) 

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 {
    public static final SimpleDateFormat date_sdf = new SimpleDateFormat("yyyy-MM-dd");

    public static String formatDate() {
        return date_sdf.format(getCalendar().getTime());
    }/*from   w w w.  j  ava 2  s.  c o m*/

    public static String formatDate(Calendar cal) {
        return date_sdf.format(cal.getTime());
    }

    public static String formatDate(Date date) {
        return date_sdf.format(date);
    }

    public static String formatDate(long millis) {
        return date_sdf.format(new Date(millis));
    }

    public static String formatDate(String pattern) {
        return getSDFormat(pattern).format(getCalendar().getTime());
    }

    public static String formatDate(Calendar cal, String pattern) {
        return getSDFormat(pattern).format(cal.getTime());
    }

    public static String formatDate(Date date, String pattern) {
        return getSDFormat(pattern).format(date);
    }

    public static Calendar getCalendar() {
        return Calendar.getInstance();
    }

    public static Calendar getCalendar(long millis) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(millis));
        return cal;
    }

    private static SimpleDateFormat getSDFormat(String pattern) {
        return new SimpleDateFormat(pattern);
    }
}

Related

  1. formatarData(String pattern, Date data)
  2. formatarDataArquivo(Date data)
  3. formatAsCassandraDate(Date date)
  4. formatAsNumber(Date date)
  5. formatBySlashForm(Date aDate)
  6. formatDate(Calendar calendar, String format)
  7. formatDate(Date date, String datePattern)
  8. formatDate(Date date, String format)
  9. formatDate(Date date, String format)