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;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String format() {
        Date date = new Date();
        return dateFormat.format(date);
    }//  ww  w .j av  a2s  .c  om

    public static String format(String datestr) {
        Date date;
        try {
            date = dateFormat.parse(datestr);
        } catch (ParseException e) {
            date = new Date();
        }
        return dateFormat.format(date);
    }
}

Related

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