Java Date Format formatDate(Date date)

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

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Date date) 

Method Source Code

//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final SimpleDateFormat DB_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");

    public static String formatDate(Date date) {
        return format(date, "yyyy-MM-dd");
    }//www .  j  av a  2s .  com

    public static Long format(Date date) {
        return Long.parseLong(DB_FORMAT.format(date));
    }

    public static String format(Long date, String pattern) {
        try {
            Date d = DB_FORMAT.parse(String.valueOf(date));
            return format(d, pattern);
        } catch (ParseException e) {
            return "";
        }
    }

    public static String format(Date date, String pattern) {
        return new SimpleDateFormat(pattern).format(date);
    }

    public static Date parse(Long date) {
        try {
            return DB_FORMAT.parse(String.valueOf(date));
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. formatDate(Date date)
  2. formatDate(Date date)
  3. formatDate(Date date)
  4. formatDate(Date date)
  5. formatDate(Date date)
  6. formatDate(Date date)
  7. formatDate(Date date)
  8. formatDate(Date date)
  9. formatDate(Date date)