Convert Milliseconds to date value in string - Android java.util

Android examples for java.util:Date Convert

Description

Convert Milliseconds to date value in string

Demo Code

import android.text.TextUtils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

public class Main{
    public static final String dateFormatYMDHMS = "yyyy-MM-dd HH:mm:ss";
    public static String convertMillis2DateStr(long millis, String format) {
        return new SimpleDateFormat(format, Locale.CHINA).format(new Date(
                millis));//from  ww  w .  ja v  a2 s. co m
    }

    public static String convertMillis2DateStr(long millis) {
        return new SimpleDateFormat(dateFormatYMDHMS, Locale.CHINA)
                .format(new Date(millis));
    }

}

Related Tutorials