Created
November 7, 2018 12:14
-
-
Save atog/85e5d5ed2c5941c5f6a8abe1bb2c914e to your computer and use it in GitHub Desktop.
Simple Java Android JSON API call to get Current DateTime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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