0

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"?

mum
  • 1,637
  • 11
  • 34
  • 58

3 Answers3

1
  1. Construct a Date object with the Date(long) constructor.

  2. Use a SimpleDateFormat to format to string with your format pattern.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • Can you see this please http://stackoverflow.com/questions/22576049/gallery-has-stopped-while-cropping-image-in-kitkat-nexus7?? – Piyush Mar 22 '14 at 10:09
1
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);
Abdullah Shoaib
  • 2,065
  • 2
  • 18
  • 26
1

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);
GaidinBDJ
  • 46
  • 2