One feature that you often find yourself in need of when programming is the ability to work with dates and times.
The design for this app is very simple, requiring just 6 components:
Everything put together looks like this:
1. Create a variable
Let’s start by creating a local variable in our app to store the response from the API.
JSON is a common data interchange format, and is used widely to transmit information. Thankfully for us, Thunkable makes it really easy to work with JSON data.
2. Make an API Request
Some APIs will require you to enter a username and password, or an access token, but this is not the case for the World Clock API.
Click on this link to see the JSON that this request returns.
3. Working with Objects
There are several name/value pairs in the response. In order to see a specific one, convert the JSON into an object.
From that object use the “get property” block to read the value we want. In our case we use
dayOfTheWeek to find out what day it is.
4. Parsing Text
Another name in our JSON response is
currentDateTime. The corresponding value contains both the date and the time.
The first 10 characters of the value are the date in the format: YYYY-MM-DD, so this is why we only get the first 10 characters.
If we want to get the time we get the 5 characters from letter #12 to letter #16. We need to use 5 characters because the time is in the format “HH:mm”
If you want to use this app as a reference then you can create your own copy by clicking on the link below