Java yyyy formatDate(Date date, String pattern)

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

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Date date, String pattern) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Main {
    private static final Lock LOCK = new ReentrantLock();

    public static String formatDate(Date date) {
        return formatDate(date, "yyyy-MM-dd");

    }//from  w  ww. j av  a 2 s .c o m

    public static String formatDate(Date date, String pattern) {

        LOCK.lock();
        try {
            DateFormat fmt = new SimpleDateFormat(pattern);
            return fmt.format(date);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            LOCK.unlock();
        }
    }
}

Related

  1. formatDate(Calendar calendar, String format)
  2. formatDate(Date date, String datePattern)
  3. formatDate(Date date, String format)
  4. formatDate(Date date, String format)
  5. formatDate(Date date, String outputPattern)
  6. formatDate(Date date, String pattern)
  7. formatDate(Date date, String pattern)
  8. formatDate(Date date, String pattern)
  9. FormatDate(Date date, String sf)