Java Hour Format formatDate(Calendar currentDate, String pattern)

Here you can find the source of formatDate(Calendar currentDate, String pattern)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Calendar currentDate, String pattern) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static String formatDate(Calendar currentDate, String pattern) {
        if (currentDate == null || pattern == null) {
            throw new NullPointerException("The arguments are null !");
        }/*w w w. ja  va2  s.  co  m*/
        Date date = currentDate.getTime();
        return formatDate(date, pattern);
    }

    public static String formatDate(Date date, String pattern) {
        if (date == null || pattern == null) {
            throw new NullPointerException("The arguments are null !");
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

    public static String formatDate(String currentDate, String pattern) throws java.text.ParseException {
        if (currentDate == null || pattern == null) {
            throw new NullPointerException("The arguments are null !");
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse(currentDate);
        sdf.applyPattern(pattern);
        return sdf.format(date);
    }
}

Related

  1. formatCreationDate(String creationDate)
  2. formatCurrentDateForDebug()
  3. formatCurrentTime()
  4. formatCurrentTime()
  5. formatCurrentTime(final String format)
  6. formatDate(Calendar time)
  7. formatDate(Date d, String pattern, TimeZone tz)
  8. formatDate(Date d, TimeZone tz)
  9. formatDate(Date date, boolean includeTime)