Provides a user friendly Calendar object as a String. - Java java.util

Java examples for java.util:Calendar Format

Description

Provides a user friendly Calendar object as a String.

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar c = Calendar.getInstance();
        System.out.println(getDisplayableDate(c));
    }/*from   w  w  w .  j  ava  2 s .  co  m*/

    /**
     * Provides a user friendly Calendar object as a String.
     * @param c the Calendar to reformat
     * @return the reformat Calendar as a String (e.g., Sat, Jul 12, 2014)
     */
    public static String getDisplayableDate(Calendar c) {
        SimpleDateFormat f = new SimpleDateFormat("EEE, MMM d, yyyy");
        return f.format(c.getTime()).toString();
    }
}

Related Tutorials