Java Long Number to Date format(Long date, String pattern)

Here you can find the source of format(Long date, String pattern)

Description

format

License

Open Source License

Declaration

public static String format(Long date, String pattern) 

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 Long format(Date date) {
        return Long.parseLong(DB_FORMAT.format(date));
    }/*from  w  w  w . j a va 2  s  .c  o m*/

    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. dateToString(long date)
  2. dateToString(long date)
  3. dateToString(long date, String formate)
  4. dateToStrLong(java.util.Date dateDate, String format)
  5. format(long date)
  6. format(long date, String pattern)
  7. format(long dateInMillis, String pattern)
  8. format(Long dateMs, String type)
  9. format(Long dateTmie, String formate)