change Timestamp To Time - Android java.util

Android examples for java.util:Date Timestamp

Description

change Timestamp To Time

Demo Code


//package com.java2s;
import android.text.TextUtils;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static SimpleDateFormat sdf;
    private static final String DEFAULT_LONG_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String changeTimestampToTime(long timestamp, String format) {
        if (TextUtils.isEmpty(format))
            sdf = new SimpleDateFormat(DEFAULT_LONG_FORMAT);
        else//from w w  w .  j a  va 2  s . c  om
            sdf = new SimpleDateFormat(format);
        return sdf.format(new Date(timestamp > 999999999999L ? timestamp
                : timestamp * 1000));
    }
}

Related Tutorials