Java Calendar Format format(Calendar cal, String pattern)

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

Description

format

License

Open Source License

Declaration

public static String format(Calendar cal, String pattern) 

Method Source Code


//package com.java2s;
/*//  www  .  jav a 2 s . c o  m
 * Copyright 2007 Sun Microsystems, Inc.
 * All rights reserved.  You may not modify, use,
 * reproduce, or distribute this software except in
 * compliance with  the terms of the License at:
 * http://developer.sun.com/berkeley_license.html
 */

import java.util.*;
import java.text.SimpleDateFormat;

public class Main {
    public static String format(Date date, String pattern) {
        // returns a String representation of the date argument,
        // formatted according to the pattern argument, which
        // has the same syntax as the argument of the SimpleDateFormat
        // class
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);

        return formatter.format(date);
    }

    public static String format(Calendar cal, String pattern) {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);

        return formatter.format(calendarToDate(cal));
    }

    public static Date calendarToDate(Calendar cal) {
        return cal.getTime();
    }
}

Related

  1. calToString(Calendar cal)
  2. format(Calendar cal)
  3. format(Calendar cal)
  4. format(Calendar cal, String format)
  5. format(Calendar calendar)
  6. format(Calendar calendar)
  7. format(Calendar calendar)
  8. format(Calendar calendar)