Date Time conversion Web App

  

Hi. I do not really know much about web apps, but I wanted to try building a mini web app to serve as the backend for a mobile app that I made. It seems that web apps do not auto convert the time in the server back to our own timezone when using currdatetime()?

Eg. I saved at 8.44pm (GMT+8) but it gave me the gmt timing.

This was my expression for the timing on the right.

If(EntryTable.List.Current.Entry.IsPublished, DateTime_PrettyFormat(EntryTable.List.Current.Entry.DateTimeposted),"-")


How do I go about fixing this? Must I use the timezone component from the forge? (preferably not)

Hi

You can use the TimeZones component and using the action ConvertFromTimeZone (converts datetime from source time zone to destination time zone) when displaying a date/time to the user on the UI. 


Cheers,

Assif

Hi Li,

Where did you get that date? if you used the CurrDate() this will be the server time. If you want to convert to another timezone you need to use https://www.outsystems.com/forge/component/500/time-zone/.

If you have users in different timezones you even need to know which one they are on using js like is explain here https://stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript

If you want to use a timezone different from the server is not something simple.

Regards,

Marcelo

Hi Marcelo,


Thank you for your reply. I used CurrDateTime() as to store the datetimeposted attribute value.

To all, because I'm 100% sure that this app will be accessed only from my current location, can I simply add 8 hours to the expression when displaying the date time? I know its not a good practice, but I'm asking whether is there any problems, for example, daylight saving time? My country is singapore, so we do not observe any changes in our clocks at all. So I'm wondering whether a static forward shift in the server date time will result in inaccurate values between the dst months? 


Li Han

Solution

Hi Li,

You should use the forge component. Your timezone doesn't have daylight but maybe the timezone of the server has. The component is really easy to use. you just need to convert the CurrDateTime() to UTC and from UTC to your timezone.

Regards,

Marcelo

Solution

Marcelo Ferreira wrote:

Hi Li,

You should use the forge component. Your timezone doesn't have daylight but maybe the timezone of the server has. The component is really easy to use. you just need to convert the CurrDateTime() to UTC and from UTC to your timezone.

Regards,

Marcelo

Hi sorry, thanks for your advice so far, can I ask one last question? It seems that when I use CurrDateTime() on the web app to upload a record to an entity, and when I retrieve that record through my front end mobile app, the correct date and time is displayed (my own timezone GMT+8).

I understood that the mobile app converts datetime from the device timezone to utc in the server, and back to the device timezone when the record is retrieved. My question is, how was the server/my mobile app able to correctly convert the utc timing to my correct timezone when I uploaded the record from my WEB APP instead? (because if it is somehow able to do so, isn't it weird that the web app itself can't auto convert as well?)


Hi Li,

Yes mobile apps do that. Dunno how and why they do that and not the web apps. But maybe because the apps installed on the device and is easy to access the timezone. While on web apps nothing is installed on client side and you need to use JS to know the timezone and this run outside outsystems control.

Regards,

Marcelo