Java Calendar Format format(Calendar calendar, String pattern)

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

Description

Formats the given Calendar while considering the time zone information.

License

Open Source License

Parameter

Parameter Description
calendar a parameter
pattern a parameter

Declaration

public static String format(Calendar calendar, String pattern) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {
    /**/*from  w w w .  ja  v  a 2s.  c  o m*/
     * Formats the given {@link Calendar} while considering the time zone
     * information.
     * 
     * @param calendar
     * @param pattern
     * @return
     */
    public static String format(Calendar calendar, String pattern) {
        return format(calendar, new SimpleDateFormat(pattern));
    }

    /**
     * Formats the given {@link Calendar} while considering the time zone
     * information.
     * 
     * @param calendar
     * @param dateFormat
     * @return
     */
    public static String format(Calendar calendar, DateFormat dateFormat) {
        dateFormat.setTimeZone(calendar.getTimeZone());
        return dateFormat.format(calendar.getTime());
    }
}

Related

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