Java Hour Format formatterDate(Date date, byte format)

Here you can find the source of formatterDate(Date date, byte format)

Description

This method formats a date using the Brazilian convention

License

Open Source License

Parameter

Parameter Description
date a parameter

Return

formatted date

Declaration

public static String formatterDate(Date date, byte format) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*from ww  w  . j  a  va 2 s  .  c  o  m*/
     * This method formats a date using the Brazilian convention
     * 
     * @param date
     * @return formatted date
     */
    public static String formatterDate(Date date, byte format) {
        // checking date
        if (date == null) {
            return "";
        }

        // creating simple date formatter instance
        SimpleDateFormat simpleDateFormat;
        switch (format) {
        case 1:
            simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
            break;

        case 2:
            simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
            break;

        default:
            simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
            break;
        }

        // formatting date
        String formattedDate = simpleDateFormat.format(date);

        // return formatted date
        return formattedDate;
    }
}

Related

  1. formattedDate(java.util.Date date, String formatString)
  2. formattedDateToDate(String str)
  3. formattedStringToDate(String date)
  4. formattedTime(long epochTime)
  5. formattedTimeForFilenames()
  6. formatterFor(final Thread t)
  7. formatTime(Date d)
  8. formatTime(Date d)
  9. formatTime(Date date)