Helper method to get the date and time from timestamp. - Android java.util

Android examples for java.util:Calendar

Description

Helper method to get the date and time from timestamp.

Demo Code


//package com.java2s;

import java.sql.Date;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class Main {
    /**/*  w  w  w. j  ava 2  s. c  om*/
     * Helper method to get the date and time from timestamp. Converts the Timestamp in Milliseconds to Date and Time and then
     * formats the Date object with {@link Format} and returns the String of Date and Time separately respectively
     *
     * @return String[] containing Date and Time
     */
    public static String[] getDateAndTimeSeparate(long timestamp) {
        Date date = new Date(timestamp);
        Format dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss",
                Locale.US);
        String dateTime = dateFormat.format(date);
        return dateTime.split(" ");
    }
}

Related Tutorials