Android - get date time from SMS timestamp in mili

2020-02-14 08:56发布

问题:

is it possible to convert Sms table date value e.g. 1293457709636 (miliseconds) to meaningful Date time value.

回答1:

just do

long ms = 1293457709636; // or whatever you have read from sms
Date dateFromSms = new Date(ms);


回答2:

You can convert Sms table date in to meaningful Date time like this.

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
Calendar calendar = Calendar.getInstance();
long now = 1293457709636L;
calendar.setTimeInMillis(now);
Log.i("time", "time"+formatter.format(calendar.getTime()));