Java Hour Format format(java.util.Date date, String format)

Here you can find the source of format(java.util.Date date, String format)

Description

format

License

Open Source License

Declaration

public static String format(java.util.Date date, String format) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static String format(java.util.Date date, String format, Calendar calendar) {
        String result = "";
        try {//from  w w  w.  java  2  s  .  c  om
            if (date != null) {
                java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
                if (calendar != null) {
                    sdf.setCalendar(calendar);
                }
                result = sdf.format(date);
            }
        } catch (Exception e) {
        }

        return result;
    }

    public static String format(java.util.Date date, String format) {
        return format(date, format, null);
    }

    public static String format(long times, String format) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(times);
        return format(calendar.getTime(), format);
    }

    public static String getTime() {

        Date currentTime = new Date();

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String dateString = formatter.format(currentTime);

        String min;

        min = dateString.substring(14, 16);

        return min;

    }
}

Related

  1. format(double number, int decimalPlace)
  2. format(final Date date)
  3. format(final Date date)
  4. format(final Date date)
  5. format(int level, String message, String source, boolean verbose)
  6. format(List list, int scale)
  7. format(long time)
  8. format(long time)
  9. format(Number price)