Java Calendar Format formatCalendar(Calendar calendar)

Here you can find the source of formatCalendar(Calendar calendar)

Description

Calendar to String format.

License

Apache License

Parameter

Parameter Description
calendar Calendar instance

Return

Formatted date string as yyyyMMddHHmmss, null if Calendar is null.

Declaration

public static synchronized String formatCalendar(Calendar calendar) 

Method Source Code

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

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

public class Main {
    /**/*from w  w  w . j ava  2 s .  co m*/
     * Calendar to String format.
     *
     * Method is synchronized because instances of SimpleDateFormat are not thread safe.
     *
     * @param calendar Calendar instance
     * @return Formatted date string as yyyyMMddHHmmss, null if Calendar is null.
     */
    public static synchronized String formatCalendar(Calendar calendar) {
        if (calendar == null)
            return null;

        SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");

        DATE_FORMAT.setCalendar(calendar);
        return DATE_FORMAT.format(calendar.getTime());
    }
}

Related

  1. format(final Calendar cal)
  2. formatarData(Calendar data)
  3. formatCalendar(Calendar calendar)
  4. formatCalendar(Calendar calendar)
  5. formatCalendar(Calendar calendar)
  6. formatCalendar(Calendar objCal, String strFormat)
  7. formatCalendarTS(Calendar value)
  8. formatCalendarXsdZulu(Calendar c, int millisDigits)
  9. formatDate(Calendar c)