Skip to content

Instantly share code, notes, and snippets.

@nicksuch
nicksuch / UdacityAndroid-JSONHelper.java
Last active September 15, 2018 03:12
Helper methods for JSON parsing for Udacity's Developing Android Apps. Sunshine app, Lesson 2: https://www.udacity.com/course/viewer#!/c-ud853/l-1469948762/e-1630778644/m-1630778645
/* The date/time conversion code is going to be moved outside the asynctask later,
* so for convenience we're breaking it out into its own method now.
*/
private String getReadableDateString(long time){
// Because the API returns a unix timestamp (measured in seconds),
// it must be converted to milliseconds in order to be converted to valid date.
Date date = new Date(time * 1000);
SimpleDateFormat format = new SimpleDateFormat("E, MMM d");
return format.format(date).toString();
}