Java Calendar Format format(Calendar calendar, String formatString)

Here you can find the source of format(Calendar calendar, String formatString)

Description

format

License

Apache License

Declaration

public static String format(Calendar calendar, String formatString) 

Method Source Code


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

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

public class Main {
    public static String format(Date date, String formatString) {
        if (date == null)
            return "";
        SimpleDateFormat frmt = new SimpleDateFormat(formatString);
        return frmt.format(date);
    }// w w  w  . ja v  a  2  s  .  co  m

    public static String format(Date date, String formatString, TimeZone timezone) {
        if (date == null)
            return "";
        SimpleDateFormat frmt = new SimpleDateFormat(formatString);
        if (timezone != null)
            frmt.setTimeZone(timezone);
        return frmt.format(date);
    }

    public static String format(Calendar calendar, String formatString) {
        if (calendar == null)
            return "";
        SimpleDateFormat frmt = new SimpleDateFormat(formatString);
        Date date = calendar.getTime();
        return frmt.format(date);
    }

    public static String format(Calendar calendar, String formatString, TimeZone timezone) {
        if (calendar == null)
            return "";
        SimpleDateFormat frmt = new SimpleDateFormat(formatString);
        if (timezone != null)
            frmt.setTimeZone(timezone);
        else
            frmt.setTimeZone(calendar.getTimeZone());
        Date date = calendar.getTime();
        return frmt.format(date);
    }
}

Related

  1. format(Calendar calendar)
  2. format(Calendar calendar)
  3. format(Calendar calendar)
  4. format(Calendar calendar, String format)
  5. format(Calendar calendar, String format)
  6. format(Calendar calendar, String pattern)
  7. format(Calendar current)
  8. format(Calendar self, String pattern)
  9. format(final Calendar cal)