Android Time Get getCurrentTime(String dateFormat)

Here you can find the source of getCurrentTime(String dateFormat)

Description

Returns current time with default `DATE_FORMAT`

License

Open Source License

Parameter

Parameter Description
dateFormat a parameter

Declaration

public static String getCurrentTime(String dateFormat) 

Method Source Code

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

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

public class Main {
    public static final String DATE_FORMAT = "yyyy-MM-dd G HH:mm:ss z";

    /**/*from  w  w  w .j av a  2 s.  c o  m*/
     * Returns current time with default `DATE_FORMAT`
     * @param dateFormat
     * @return
     */
    public static String getCurrentTime(String dateFormat) {
        return formatDate(Calendar.getInstance().getTime(), dateFormat);
    }

    /**
     * Format date with default `DATE_FORMAT` and default locale `Locale.KOREA`
     * @param date
     * @return
     */
    public static String formatDate(Date date) {
        return formatDate(date, DATE_FORMAT);
    }

    /**
     * Format date with `dateFormat` given and default locale `Locale.KOREA`
     * @param date
     * @param dateFormat
     * @return
     */
    public static String formatDate(Date date, String dateFormat) {
        return formatDate(date, dateFormat, Locale.ENGLISH);
    }

    /**
     * Format date
     * @param date
     *       `Date` formatted to
     * @param dateFormat
     *       Date format like 'yyyy-MM-dd'
     * @param locale
     *       Locale for date format.
     * @return
     *      Formatted date string 
     */
    public static String formatDate(Date date, String dateFormat,
            Locale locale) {
        SimpleDateFormat format = new SimpleDateFormat(dateFormat, locale);
        return format.format(date);
    }
}

Related

  1. getCurrentTime()
  2. getFormatShortTime(Date date)
  3. getFormatTime(Date date)
  4. getCurTimeByFormat(String format)
  5. getCurTimeByFormat(String format)
  6. getDate(String time)
  7. getDate(String time)
  8. getDateLabel(long time)
  9. getDateTime()