Java Calendar Format toShort(Calendar calendar)

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

Description

to Short

License

Open Source License

Declaration

public static String toShort(Calendar calendar) 

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 {
    public static String toShort(Calendar calendar) {
        return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(calendar.getTime());
    }//from   w  w w.  j av  a 2  s.  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. getDate(Calendar cal, String dateFormat)
  2. getDate(Calendar cal, String dateFormat)
  3. print(Calendar[] calendar)
  4. printCalendar(Calendar cal)
  5. toInfo(Calendar calendar)
  6. toSimpleFormat(Calendar cal)
  7. toW3C(Calendar cal)