Java Hour Format format(Date date)

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

Description

Format the date.

License

Open Source License

Parameter

Parameter Description
date the date

Return

the formated date

Declaration

public static String format(Date date) 

Method Source Code


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

import java.text.DateFormat;

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

public class Main {
    /** The Constant UTC_TIME_ZONE. */
    public final static TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC");
    /** The Constant DATE_TIME_PATTERN. */
    public final static String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";

    /**// ww  w.  ja v  a2  s .co  m
     * Format the date.
     *
     * @param date the date
     * @return the formated date
     */
    public static String format(Date date) {
        DateFormat df = getThreadLocalDateFormat();
        return df.format(date);
    }

    /**
     * Format the date.
     *
     * @param current the current
     * @return the string
     */
    public static String format(Calendar current) {
        return format(current.getTime());
    }

    /**
     * Gets the thread local date format.
     *
     * @return the thread local date format
     */
    private static DateFormat getThreadLocalDateFormat() {
        DateFormat result = new SimpleDateFormat(DATE_TIME_PATTERN);
        result.setTimeZone(UTC_TIME_ZONE);
        return result;
    }
}

Related

  1. format(Date date)
  2. format(Date date)
  3. format(Date date)
  4. format(Date date)
  5. format(Date date)
  6. format(Date date)
  7. format(Date date)
  8. format(Date date)
  9. format(Date date)