I am developing one GPS Application. Which will send the location data to server for every one hour.
In this I am using following code:
location.getLatitude();
location.getLongitude();
location.getTime();
with this code I am getting Latitude and Longitude correctly and Time also, but I am getting some 13 digits number instead of the time. I done some research on that, I found that is an seconds for of the current time.
so now I need to convert that 13 digit number in to the specific format.
解决方案
Location#getTime() returns "the UTC time of this fix, in milliseconds since January 1, 1970."
This is exactly the same behavior as java.util.Date#getTime(). I'm not clear on what you'd like to do with this time data, but if you'd like to convert the Location's time into a java.util.Date, you can do it like this:
long time = location.getTime();
Date date = new Date(time);
Now it is somewhat easier to work with. If you'd like to create a particular string output format of that date, use SimpleDateFormat:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String text = sdf.format(date);
System.out.println(text); // prints something like 2011-01-08 13:35:48
That said, if all you'd like to do is get the current time (which is what it sounds like you're trying to do) you don't need a Location at all:
Date now = new Date();
That's it!
Does that help? If not, could you clarify what you're trying to do?