Skip to content

Instantly share code, notes, and snippets.

@atog
Created November 7, 2018 12:14
Show Gist options
  • Save atog/85e5d5ed2c5941c5f6a8abe1bb2c914e to your computer and use it in GitHub Desktop.
Save atog/85e5d5ed2c5941c5f6a8abe1bb2c914e to your computer and use it in GitHub Desktop.
Simple Java Android JSON API call to get Current DateTime
public Calendar getWorldClockCurrentDateTime() {
URLConnection connection = new URL("http://worldclockapi.com/api/json/cet/now").openConnection();
BufferedReader bfr = new BufferedReader(new InputStreamReader(connection.getInputStream()));
JSONObject dateTimeJson = new JSONObject(bfr.readLine());
Date date = dateParser.parse(dateTimeJson.getString("currentDateTime"));
Calendar rvalue = Calendar.getInstance();
rvalue.setTime(date);
return rvalue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment