Java Time Format getTime(String timeFormat)

Here you can find the source of getTime(String timeFormat)

Description

Gets the time at the instant of invocation.

License

Artistic License

Parameter

Parameter Description
timeFormat The format for the time to be in, i.e. "dd MM yyyy hh:mm:ss"

Return

The time string at the time of invocation, formatted per the timeFormat .

Declaration

public static String getTime(String timeFormat) 

Method Source Code


//package com.java2s;
//License from project: Artistic License 

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

public class Main {
    /**//  w w  w  .  j  a  v a 2s .c om
     * Overload of {@link #getTime(String)}.<br />
     * <br />
     * Gets the date at the instant of invocation, formatted as {@code dd MM yyyy}, i.e. {@code 10 April 2014}.
     *
     * @return The date, formatted as {@code dd MM yyyy}.
     * @see #getTime(String)
     */
    public static String getTime() {
        return getTime("dd MM yyyy");
    }

    /**
     * Gets the time at the instant of invocation. Includes date.
     *
     * @param timeFormat The format for the time to be
     *                   in, i.e. {@code "dd MM yyyy hh:mm:ss"}
     * @return The time string at the time of invocation,
     * formatted per the {@code timeFormat}.
     */
    public static String getTime(String timeFormat) {
        return new SimpleDateFormat(timeFormat).format(Calendar.getInstance().getTime());
    }
}

Related

  1. getTime(long time, int timeFormat)
  2. getTime(String dateStr, String format)
  3. getTime(String dateStr, String formate)
  4. getTime(String format)
  5. getTime(String format, String date)
  6. getTimeAfter(int field, int amount, String formatStr)
  7. getTimeAsString(final Date date, final String format)
  8. getTimeAsString(String timeFormatAsString)
  9. getTimeByDate(Date date, String timeFormat)