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

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

Description

formate Date

License

Open Source License

Declaration

public static String formateDate(Long 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 {
    public static final String DATE_FORMAT_D = "EEE, d MMM yyyy HH:mm:ss Z";

    public static String formateDate(Date date, String format) {
        if (date == null) {
            return "";
        }//  w  w w  . j  a va2s.com
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }

    public static String formateDate(String date, String format) {
        if (date == null) {
            return "";
        }
        Date date2 = parseDate(date, format);
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date2);
    }

    public static String formateDate(Long date, String format) {
        if (date == null) {
            return "";
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(new Date(date));
    }

    public static Date parseDate(String date, String format) {
        if (date == null) {
            return null;
        }
        date = date.trim();
        if (date.length() == 0) {
            return null;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        try {
            return dateFormat.parse(date);
        } catch (ParseException e) {
            //throw new RuntimeException(e);
            return null;
        }
    }

    public static Date parse(String date) throws ParseException {
        if (date == null) {
            return null;
        }
        date = date.trim();
        if (date.length() == 0) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT_D, Locale.US);
        return format.parse(date);
    }
}

Related

  1. formatDateTime(long date)
  2. formatDateTime(long millis)
  3. formatDateTime(long time)
  4. formatDateTime(long timestampEpoch)
  5. formatDateTimeStamp(final long timeInMillis, final String dateFormatString)
  6. formatEpoch(long date)
  7. formatHttpDate(long d)
  8. formatHTTPDate(long pTime)
  9. formatHttpDate(long time)