• Login
  • login to access premium content (it's free).

How to get UTC+0 / GMT

This seems like a very simple question with a simple answer.

NOW

A simple use of NOW will only return the time and date portion of what the underlying server is reporting. For example if you were to type date from the command line on your server you would get something like this...

$ date
Wed Nov 19 11:18:56 PST 2014

And then if you run NOW in your html/os code you get something like this...

11/19/2014 11:18

Notice the timezone is no where to be seen. And to complicate things if you use the Aestiva Control Panel to modify your time to say add 120 minutes to the server time then the Aestiva Time will return...

11/19/2014 13:18

And once again the concept of which timezone this represents is lost.

Thankfully newer versions of HTML/OS include a nice function called UTCOFFSET(now) in the example listed above UTCOFFSET(now) would return -0800, but it would return that regardless of any time modifications you might have made with the time control panel.

So in order to get the UTC+0 time on your server you can use the function ADDMINUTES() to subtract the UTCOFFSET times 60 but then you will also have to subtract the minutes offset you may have entered into your Time Control Panel.

Here is a function that encapsulates these two arithmetic operations to give you the true UTC+0 or GMT date and time.

function nowUTC() locals u,s,timeconf do
 copy file="/system/conf/time.conf" ts=',' to timeconf /copy
 if timeconf[1,1]='ERROR' then timeconf[1,1]=0 /if
 if timeconf[1,1]=''      then timeconf[1,1]=0 /if
 u=utcoffset(now)
 s=left(u,1)
 u=middle(u,2,3)
 u=u+0
 if s='-' then u=u*-1 /if
 return addminutes(now,(u*-60)-timeconf[1,1]) /return
/function 

Let me know in the comments if this works for you and if not why.