Java Locale Format formatDate(Date date, String format)

Here you can find the source of formatDate(Date date, String format)

Description

format date

License

Open Source License

Parameter

Parameter Description
date yyyymmdd
format a parameter

Declaration

public static String formatDate(Date date, String format) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {
    /**//from  w w  w.j a  v a2  s  .  c  o  m
     * format date
     * 
     * @param date yyyymmdd
     * @param format
     * @return
     */
    public static String formatDate(Date date, String format) {
        SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US);
        String sysdate = formatter.format(date);
        return sysdate;
    }

    /**
     * format date
     * 
     * @param date yyyymmdd
     * @param format
     * @return Date
     * @throws ParseException
     */
    public static Date formatDate(String date, String format) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.US);
        return formatter.parse(date);
    }
}

Related

  1. formatBytes(long byteCount, Locale locale)
  2. formatBytesForDisplay(long amount)
  3. formatComma(String number)
  4. formatDate(Calendar cal, String format)
  5. formatDate(Date date, String format)
  6. formatDate(Date date, String format, String localeText)
  7. formatDate(Date date, String pattern)
  8. formatDate(Date date, String pattern)
  9. formatDate(Date date, String pattern, Locale locale)