Java Calendar Format format(Calendar cal)

Here you can find the source of format(Calendar cal)

Description

Null-safe method to display a Calendar as a formatted String .

License

Open Source License

Parameter

Parameter Description
cal the Calendar

Return

the formatted

Declaration

public static String format(Calendar cal) 

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 {
    private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

    /**//from   w  ww  .j  a v a  2 s.  c  o m
     * Null-safe method to display a {@link Calendar} as a formatted {@link String}.
     * <p/>
     * Format template is {@code yyyy-MM-dd'T'HH:mm:ss}.
     *
     * @param cal the {@link Calendar}
     * @return the formatted {@link String}
     */
    public static String format(Calendar cal) {
        return cal == null ? "null" : "<" + df.format(cal.getTime()) + ">";
    }
}

Related

  1. calToString(Calendar cal)
  2. format(Calendar cal)
  3. format(Calendar cal, String format)
  4. format(Calendar cal, String pattern)
  5. format(Calendar calendar)