I get time from location, it return the UTC time of this fix, in milliseconds since January 1, 1970.
long gpstime = location.getTime();
EX: gpstime =1395477208249
How convert to format "yyyyMMddhhmmss"
?
Construct a Date
object with the Date(long)
constructor.
Use a SimpleDateFormat
to format to string with your format pattern.
Date date = new Date(gpstime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT-4"));
String formattedDate = sdf.format(date);
First of all just want to make sure that location.getTime() will return the time of the fix, not the current time. You can convert to local with:
Calendar calendar = Calendar.getInstance();
TimeZone timezone = calendar.getTimeZone();
SimpleDateFormat formattedDate = new SimpleDateFormat("yyyyMMddhhmmss");
formattedDate.setTimeZone(timezone);