Java Hour Format formatShortDate(java.util.Date date)

Here you can find the source of formatShortDate(java.util.Date date)

Description

format Short Date

License

Open Source License

Declaration

public static String formatShortDate(java.util.Date date) 

Method Source Code


//package com.java2s;

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

import java.util.Date;

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

    public static String formatShortDate(java.util.Date date) {
        if (date == null) {
            return "";
        }//from w ww . j a  v a 2s . c o  m
        return formatter.format(date);
    }

    public static String format() {
        Date date = new Date();
        return dateFormat.format(date);
    }

    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. formatRFC822(Date date, Locale locale)
  2. formatRFC822(Date date, String timezone)
  3. formatRfc822Date(Date date)
  4. formatRuntime(long runtime)
  5. formatSDate(java.util.Date date)
  6. formatShortTime()
  7. formatSimpleTimeAndDateString(Date date)
  8. formatSingleFractionHours(Double updatedHours)
  9. formatSQL(Date date)