Java Time Format getTimeByFormat(Date date, String format)

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

Description

Gets the time by format.

License

Open Source License

Parameter

Parameter Description
date the date
format the format

Return

the time by format

Declaration

public static String getTimeByFormat(Date date, String format) 

Method Source Code


//package com.java2s;
/*//www  .j a v  a  2  s .c o  m
 * Copyright(C) 2016 thuebannhadat.com.vn. All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * thuebannhadat.com.vn. You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the license
 * agreement you entered into with thuebannhadat.com.vn.
 */

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {
    /**
     * Gets the time by format.
     *
     * @param date
     *            the date
     * @param format
     *            the format
     * @return the time by format
     */
    public static String getTimeByFormat(Date date, String format) {
        return format(date, format, Locale.ENGLISH);
    }

    /**
     * Format date to String.
     *
     * @param date
     *            the date
     * @param format
     *            the format
     * @param locale
     *            the locale
     * @return the string
     */
    public static String format(Date date, String format, Locale locale) {

        if (date != null && format != null && locale != null) {
            return new SimpleDateFormat(format, Locale.ENGLISH).format(date);
        }
        return null;
    }
}

Related

  1. getTime(String timeFormat)
  2. getTimeAfter(int field, int amount, String formatStr)
  3. getTimeAsString(final Date date, final String format)
  4. getTimeAsString(String timeFormatAsString)
  5. getTimeByDate(Date date, String timeFormat)
  6. getTimeCount(String from, String to, String format)
  7. getTimeCount(String from, String to, String format)
  8. getTimeFormat()
  9. getTimeFormat()