I see you asking the same question in multiple communities. Only ask in the community of the builder you are using.
Did you try something?
You can search for API...
And how about looking for yourself first, e.g. here:
https://puravidaapps.com/extensions.php
"TimeTools
", "DateTools
"
Yes, because I build on both platforms but in neither I can solve my problem friend ... I'm very sorry ... but I just wanted to solve my problem
Yes friend. I tried but they only change the time .. my problem is: I get the date from a json wn gmt0 format I want the user to see the information in the app when they see the information in the time zone they are in
OK. It would be nice if you could provide an example of what you want to happen. Please include the url of the json you access.
Here is a tool using the FormatDateTime block that probably would help. Not providing a link to the url and your Blocks preclude a specific application solution.
Use the above information along with a Clock component to convert the information in the time zone they are in using the UTC offset information. In the example instance you need to subtract 05 hours from the user's device's system time perhaps and write code to determine whether that process affects the data.
The Z, zzzz, X 'instructions you provide in the pattern determine what result you get regarding to the UTC zone information of a users' device. Provide a pattern like X to grab only the -05 in the example (time difference). Try it. Only you know what you want to do or expect to happen.
When you arrive at a solution, please post your solution. Thanks.
Regards,
Steve
APP Inventor – clock object and timezones
Thanks to SteveJG regarding using the X formatdatetime option
Trying the clock object, as I want to send a perfect number to excel to get the date in the actual timezone of the phone. And sending formatted text to excel it treats it as text, and it messes up the date, as it keeps on converting dates (i.e. in European format 01-02-2021, excel converts it to American, and it becomes 02-01-2021)
When I started sending the actual days after 1-1-1900 (which is the excel baseline value for days after), App inventor uses 1-1-1970. Using the formula per label2.txt to convert msec to days and adding 25569 for the difference between 1-1-1900 to 1-1-1970
Doing this add just after midnight, the date I got in excel was from yesterday (I am in timezone +1)
Giving me the feeling that systemtime and clock.now is actually giving me the value in UTC and not actual devicetime based in its timezone. I would have assumed that systemtime, yes would be ticks after 1-1-1970 in baseline UTC, but clock.now would actually be the offset time based on the timezone.
During the next day at again just after 12 noon, tried this again and the lavel2.text gave me a value of xxxx.47571, while after noon should be higher then >0,5 as such confirmed this assumption.
As such started playing with formatdatetime to find a workaround, and the pattern X ( as suggested by SteveJG!). Pattern x gives me the numerical difference from UTC based on my phones timezone. And the tested result showed this perfectly to be indicated. +1.
Putting the X in action
So we convert the X value into mscec, and then add that to the clock return msec. Doing this it got me the actual days since 1-1-1900 to >0,5 so now showing the clock in my actual timezone.
Just to assure it actually works, changed the timezone of the phone to UTC-03. And as well this showed perfectly the UTC time minus in 10800000 msec which is -3 hours.
Anyway was looking for a solution to this, and this seems to work. Have been looking around and saw some posts but nothing that told me how to get clock in actual timezone, until I saw SteveJG suggestion on getting the timezone difference in value. Maybe there is an easier way to do this, and more then happy to get feedback from other people, but in case there is nothing at the moment that can deal with this, wanted to share to the forum in case it is useful for somebody.
Very simple..
Use this address in web component and when you text as JSON format , pull the date and time alone in separate label
`
`
Thanks
that works as well,
anyway then my suggestion might help if people need it in offline mode or if the api that delivers the api is offline
always great to share and learn!
Serge
Be interested to know if this is of any help ?
<!DOCTYPE html>
<html>
<meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
<head>
<title>Time</title>
</head>
<body>
<script>
document.write(new Date());
</script>
</body>
</html>
showtime.txt (216 Bytes)
(change txt to html and run as asset in webviewer: http://localhost/showtime.html)
Just a small update.. X if you are in GMT instead of being 0, it gives back Z. As such the calculation fail
You would need to put a test on it
I think this is a similar problem:
I have this json:
{"high": "38463.90", "last": "35324.30", "timestamp": "1642882399", "bid": "35309.35", "vwap": "35828.33", "volume": "5839.36285258", "low": "34000.00", "ask": "35352.96", "open": "36447.37"}
The timestamp is GMT.
If I use the Clock1.FormatDateTime function:
I can display the date based on the devices current timezone so that it looks like this:
EXAMPLE: 2022/01/22 13:29:17 MST
However, what I want, is to display the time as UTC, like this:
EXAMPLE: 2022/01/22 20:29:17 UTC
Any suggestions how to accomplish this?
Thanks in advance for your response(s).
MST is 7 hours behind of GMT
so, something like adding 7 hours should work. Your Blue Blocks are 'simulated' to be 2022/01/22 13:29:17 in the MakeFromPartsBlock
I think I have it worked out...screwy when you have to think in two time zones, but what do you think of this:
My last question is, and referring to Serge's answer above, if I'm using the Z pattern, what happens for a device which is located in GMT?
That what the blocks above your blocks handle.
I want it to be able to work correctly in ANY time zone.
This will all depend on whether your timestamp in your json will always be GMT. If it will be then You can adjust to any timezone. Make a list and select as required. If you cannot gurantee that your timestamp will be GMT, then you will need more data to help you set your required time zone.
I can ALWAYS guarantee that the timezone of the data is in UTC, because it's a Unix Timestamp.
The adjustment is for display purposes due to the user being in different time zones.
For example:
will ALWAYS converts the timestamp to the USER's time/timezone and doesn't adjust for UTC.
My intent is to ALWAYS display the actual timestamp of the data in UTC, no matter where the device is physically located on the globe.
I'm still not sure about using "Z" to obtain the time offset for countries like the UK(Located ON GMT), countries east of GMT, or what happens when I user is moving across the International Date Line.
That is a good solution, but the problem is not the device time, but how to display the UTC time of the data on a device which is located in a different time zone that UTC/GMT.
I've considered that another option would be to simply set the time of the device to GMT, which works as a solution, but you must admit that it increases the complexity of using the device for the rest of the time you want to use it.
To me, the benefit of doing it my way is that it helps discover/understand the reset triggers for Open, High, and Low, which are not available in the API json.