I have the following script made by REXTENDED, it hasn’t worked for several weeks, the problem is in “https://showcase.api.linx.twenty57.net/UnixTime/tounix\3Fdate=now ” the page doesn’t work, you can change for another URL, I leave the script
{
:local intGoff [:tonum [/system clock get gmt-offset]]
:if ($intGoff > 93600) do={:set intGoff ((4294967296 - $intGoff) * -1)}
:local epochNow (([/tool fetch url="https://showcase.api.linx.twenty57.net/UnixTime/tounix\3Fdate=now" as-value output=user])->"data")
:set epochNow [:pick $epochNow 1 ([:len $epochNow] - 1)]
:local upTime [/system resource get uptime]
:local wPos [:find $upTime "w" -1]
:local dPos [:find $upTime "d" -1]
:local utLen [:len $upTime]
:local utSec [:pick $upTime ($utLen - 2) $utLen]
:local utMin [:pick $upTime ($utLen - 5) ($utLen - 3)]
:local utHou [:pick $upTime ($utLen - 8) ($utLen - 6)]
:local utDay 0
:local utWee 0
:if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime 0 $dPos] }
:if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = "num") do={:set utWee [:pick $upTime 0 $wPos] }
:local totUtSec ($utSec + (60 * $utMin) + (60 * 60 * $utHou) + (60 * 60 * 24 * $utDay) + (60 * 60 * 24 * 7 * $utWee))
:local epochStart ($epochNow - $totUtSec + $intGoff)
:local datetimeStart (([/tool fetch url="https://showcase.api.linx.twenty57.net/UnixTime/fromunix\3Ftimestamp=$epochStart" as-value output=user])->"data")
:set datetimeStart [:pick $datetimeStart 1 ([:len $datetimeStart] - 1)]
:put "RouterBOARD is started $datetimeStart"
}
EL DONCITO.
Jotne
October 11, 2022, 5:21am
2
Make a request to MikroTik to implement Epoch time and also to use standard time format (ISO:8601) everywhere in the RouterOS.
Should not need to be dependent of external programs.
Jotne
October 11, 2022, 11:15am
4
And that do work inside RouterOS?
completly useless on first use, the URL must return current UNIX timestamp without provide a date,
but can be used on 2nd call for convert timestamp to date
Thanks for answering friend REX, and how do I use it in the second call to convert the timestamp to the date, please help me
EL DONCITO.
If you can’t have a timestamp first, how to convert something to date?
I understand REX, and you don’t have any solution?
EL DONCITO.
to get current timestamp
https://helloacm.com/api/unix-timestamp-converter/?s=now
to convert timestamp to date string
https://helloacm.com/api/unix-timestamp-converter/?s=1665674782
to get current timestamp
https://helloacm.com/api/unix-timestamp-converter/?s=now
to convert timestamp to date string
https://helloacm.com/api/unix-timestamp-converter/?s=1665674782
this is the answer
failure: closing connection: <404 Not Found> 104.26.14.89:443 (4)
Thanks for your help kangarie, let’s wait to see what answer rextended gives us.
EL DONCITO.
I replace all occurrencies of “showcase” on this forum, except this topic, with the correct versions, thanks to @kangarie
The correct version for this topic is:
http://forum.mikrotik.com/t/convert-uptime-to-date-and-time/157724/12
Thanks again to @kangarie
REXTENDED,
if the router restarts in the afternoon because it takes the time as if it were in the morning, that is, if the router restarts at 9 am there if it takes the time well (09:00:00), but if it restarts at 3 pm takes the time 03:00:00, what is wrong?
It’s 12 hours late.
You right, the remote site have a bug
subtracting 12h to the time, do not show am/pm or the right 24h time
https://helloacm.com/api/unix-timestamp-converter/?cached&s=1666314750 “2022-10-21 01:12:30”
https://helloacm.com/api/unix-timestamp-converter/?cached&s=1666271550 “2022-10-20 01:12:30” (must be 13:12:30)
I search again another working URL.
Guys,
does anyone have any url to calculate in UNIX time.
Thanks for the help.
from timestamp
https://api.kangarie.com/time/str/1666314750
from date string
https://api.kangarie.com/time/str/2022-10-22%2001:12:30
hope this will worked
new code will be
{
:local intGoff [:tonum [/system clock get gmt-offset]]
:if ($intGoff > 93600) do={:set intGoff ((4294967296 - $intGoff) * -1)}
:local epochNow (([/tool fetch url="https://api.kangarie.com/time/str/now" as-value output=user])->"data")
:local upTime [/system resource get uptime]
:local wPos [:find $upTime "w" -1]
:local dPos [:find $upTime "d" -1]
:local utLen [:len $upTime]
:local utSec [:pick $upTime ($utLen - 2) $utLen]
:local utMin [:pick $upTime ($utLen - 5) ($utLen - 3)]
:local utHou [:pick $upTime ($utLen - 8) ($utLen - 6)]
:local utDay 0
:local utWee 0
:if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime 0 $dPos] }
:if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = "num") do={:set utWee [:pick $upTime 0 $wPos] }
:local totUtSec ($utSec + (60 * $utMin) + (60 * 60 * $utHou) + (60 * 60 * 24 * $utDay) + (60 * 60 * 24 * 7 * $utWee))
:local epochStart ($epochNow - $totUtSec + $intGoff)
:local datetimeStart (([/tool fetch url="https://api.kangarie.com/time/str/$epochStart" as-value output=user])->"data")
:put "RouterBOARD is started $datetimeStart"
}
Thanks again to @kangarie and @Rextended .
Again the same problem with the URL, does anyone have one please.