how to get GMT Offset in command?

wanted to know if there is a way to get the GMT as shown in the winbox?
because if mt gmt-oofset is +3 and I use this command:

:put ([/system clock get gmt-offset ]/3600

the resault is : 3
but if my gmt-offset is -3
the resault is : 1193043

so what can I do?


Thanks ,

Try not dividing it by 3600

but what to do if I need to create a 1 command for all my routers
and some of then are in +3 and some on -3?

is there no other way?

Thanks ,

Did you try not dividing it by 3600?
What is the result when you do that?

This is not the best way how to do this, but I managed to use this:
:put [:totime ([/system clock get gmt-offset ] - (2147483647 * 2) - 2)]

For example, if you try this :put [:totime ([/system clock get gmt-offset ]] and get some strange value, then try this :put [:totime ([/system clock get gmt-offset ] - (2147483647 * 2) - 2)].

Example:
{
:local t [:totime [/system clock get gmt-offset ]]
if ( [:len $t] != 8 ) do={
:set $t [:totime ([/system clock get gmt-offset ] - (2147483647 * 2) - 2)]
}
:put $t
}

It looks like a signed/unsigned problem. Is the value of the timezone offset incorrectly returned as unsigned, or is the division operator incorrectly treating it as unsigned?

From a quick test, I’m seeing that the gmt-offset itself is returned as unsigned (or more accurately, as a “num” value).

Technically, RouterOS does not have a signed integer type. The “num” type values are 64 bit unsigned integers. “time” values however can be negative. IMHO, that’s the type this should be returned as in general. The fix strods provided does just that - convert the “signed” 64 bit integer into a time value that is negative if necessary.

Thanks ,

Alternative

{
:local tZone [/system clock get gmt-offset];
:local tzHour;
:local tzMin;
:if ([:tonum $tZone] > 43200) do={
    :set tZone    [:totime ($tZone - (2147483647 * 2) - 2)];
    :set tzHour   [:pick $tZone 0 3];
    :set tzMin    [:pick $tZone 4 6];
} else={
    :set tZone    [:totime $tZone];
    :set tzHour   ("+".[:pick $tZone 0 2]);
    :set tzMin    [:pick $tZone 3 5];
}
:put ($tzHour.$tzMin);
}

Thanks strods

43200: Wrong value, time zones +12:45 (New Zealand), +13:00 (New Zealand, Samoa and Tonga) and +14:00 exist (Kiribati).
Do not cost nothing use at least 24 hours…

(2147483647 * 2) - 2: why not directly subtract 4294967296 (0x100000000)???

Usually Time Zone is writed with : like +01:00, not +0100


“Nice”, short and formatted.

{
:local tzmin  [/system clock get gmt-offset]
:if ($tzmin > 0x7FFFFFFF) do={:set tzmin ($tzmin - 0x100000000)}
:local tzsign "+"
:if ($tzmin < 0) do={:set tzsign "-"; :set tzmin ($tzmin * -1)}
:local tzstr  [:pick "$tzsign$[:totime $tzmin]" 0 6]
:put "Time Zone offset on this routerboard is $tzstr ($tzsign$tzmin seconds)"
}

Just the offset string

{
:local tzmin  [/system clock get gmt-offset]
:if ($tzmin > 0x7FFFFFFF) do={:set tzmin ($tzmin - 0x100000000)}
:local tzsign "+"
:if ($tzmin < 0) do={:set tzsign "-"; :set tzmin ($tzmin * -1)}
:local tzstr  [:pick "$tzsign$[:totime $tzmin]" 0 6]
:put "Time Zone offset on this routerboard is $tzstr"
}

Just the value on minutes:

{
:local tzmin  [/system clock get gmt-offset]
:if ($tzmin > 0x7FFFFFFF) do={:set tzmin ($tzmin - 0x100000000)}
:local tzsign "+"
:if ($tzmin < 0) do={:set tzsign "-"; :set tzmin ($tzmin * -1)}
:put "Time Zone offset on this routerboard is $tzsign$tzmin seconds"
}