Java Hour Format format()

Here you can find the source of format()

Description

format

License

Open Source License

Declaration

public static String format() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String format() {
        return toInfo(getCalendar());
    }//from   w  w  w  .  ja v  a2s  .c o m

    /**
     * @param date
     */
    public static String toInfo(Date date) {
        return toInfo(date, "yyyy-MM-dd HH:mm:ss");
    }

    /**
     * @return
     */
    public static String toInfo() {
        return toInfo(getCalendar().getTime(), "yyyy-MM-dd");
    }

    /**
     * @param date
     * @param dateFromat
     */
    public static String toInfo(Date date, String dateFromat) {
        SimpleDateFormat format = new SimpleDateFormat(dateFromat);
        return format.format(date);
    }

    /**
     * @param calendar
     */
    public static String toInfo(Calendar calendar) {
        return toInfo(calendar.getTime());
    }

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

    public static long getTime() {
        return getTime(getCalendar());
    }

    public static long getTime(Calendar c) {
        return c.getTimeInMillis();
    }
}

Related

  1. format()
  2. format(Calendar date)
  3. format(Date d)
  4. format(Date d)