Java Calendar Format format(Calendar current)

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

Description

Format the date.

License

Open Source License

Parameter

Parameter Description
current the current

Return

the string

Declaration

public static String format(Calendar current) 

Method Source Code


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

import java.text.DateFormat;

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

public class Main {
    /** The Constant UTC_TIME_ZONE. */
    public final static TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC");
    /** The Constant DATE_TIME_PATTERN. */
    public final static String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";

    /**/*from w  w  w.ja v a 2  s.c o  m*/
     * Format the date.
     *
     * @param date the date
     * @return the formated date
     */
    public static String format(Date date) {
        DateFormat df = getThreadLocalDateFormat();
        return df.format(date);
    }

    /**
     * Format the date.
     *
     * @param current the current
     * @return the string
     */
    public static String format(Calendar current) {
        return format(current.getTime());
    }

    /**
     * Gets the thread local date format.
     *
     * @return the thread local date format
     */
    private static DateFormat getThreadLocalDateFormat() {
        DateFormat result = new SimpleDateFormat(DATE_TIME_PATTERN);
        result.setTimeZone(UTC_TIME_ZONE);
        return result;
    }
}

Related

  1. format(Calendar cal, String pattern)
  2. format(Calendar calendar)
  3. format(Calendar calendar)
  4. format(Calendar self, String pattern)
  5. format(Calendar calendar, String format)
  6. formatCalendarXsdZulu(Calendar c, int millisDigits)
  7. formatRfc3339Calendar(Calendar cal)
  8. format(Calendar cal)
  9. format(Calendar calendar, String formatString)