Java Long Number to Date formatDate(long millis)

Here you can find the source of formatDate(long millis)

Description

format Date

License

Apache License

Declaration

public static String formatDate(long millis) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static final SimpleDateFormat date_sdf = new SimpleDateFormat("yyyy-MM-dd");

    public static String formatDate() {
        return date_sdf.format(getCalendar().getTime());
    }/*from   www  .  j a  v  a 2s .  com*/

    public static String formatDate(Calendar cal) {
        return date_sdf.format(cal.getTime());
    }

    public static String formatDate(Date date) {
        return date_sdf.format(date);
    }

    public static String formatDate(long millis) {
        return date_sdf.format(new Date(millis));
    }

    public static String formatDate(String pattern) {
        return getSDFormat(pattern).format(getCalendar().getTime());
    }

    public static String formatDate(Calendar cal, String pattern) {
        return getSDFormat(pattern).format(cal.getTime());
    }

    public static String formatDate(Date date, String pattern) {
        return getSDFormat(pattern).format(date);
    }

    public static Calendar getCalendar() {
        return Calendar.getInstance();
    }

    public static Calendar getCalendar(long millis) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(millis));
        return cal;
    }

    private static SimpleDateFormat getSDFormat(String pattern) {
        return new SimpleDateFormat(pattern);
    }
}

Related

  1. formatDate(long date, String langStr)
  2. formatDate(long dateValue)
  3. formatDate(long epochMillis)
  4. formatDate(long millis)
  5. formatDate(long millis)
  6. formatDate(long millis, Locale locale)
  7. formatDate(long millis, String dateFormat)
  8. formatDate(long millisecond, String format)
  9. formatDate(long ms)