Android Time Format formatDateAndTime(int timestamp, String pattern)

Here you can find the source of formatDateAndTime(int timestamp, String pattern)

Description

Formats a Unix timestamp in something human readable.

Parameter

Parameter Description
timestamp int - Unix timestamp (in seconds).
pattern String - Pattern to use to format the date and time.

Return

Formatted date and time.

Declaration

public static String formatDateAndTime(int timestamp, String pattern) 

Method Source Code

//package com.java2s;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    public static final long ONE_SECOND = 1000;

    /**/* w w w .  ja  va  2  s. com*/
     * Formats a Unix timestamp in something human readable.
     *
     * @see http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
     *
     * @param timestamp int - Unix timestamp (in seconds).
     * @param pattern String - Pattern to use to format the date and time.
     *
     * @return Formatted date and time.
     */
    public static String formatDateAndTime(int timestamp, String pattern) {
        long time = timestamp * ONE_SECOND;
        Date date = new Date(time);

        SimpleDateFormat formattedDate = new SimpleDateFormat(pattern,
                Locale.getDefault());
        return formattedDate.format(date);
    }
}

Related

  1. dateToString(Time t)
  2. toISO8601Date(Time date)
  3. formatDisplay(int second)
  4. formatDate(String mounthStr)
  5. dateTimeFormat(String dateTime)
  6. dateTimeFormat(String dateTime)
  7. formatDateTime(String date, String format)