命令:put [/system/resource/get uptime] 5w4d12:38:02
:global currendatetimestr do={/系统时钟:本地vdate [get date]:本地vtime [get time]:本地VGMT [:tonum [get gmt-offset]];:如果($ vgmt > 0 x7fffffff) ={:设置vgmt ($ vgmt - 0 x100000000)}:当地prMntDays [: toarray”59岁,0,0,31日90120151181212243273304334”):当地LcaseMnts [: toarray“0,1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月”):当地PcaseMnts [: toarray“0,1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月”):当地UcaseMnts [: toarray“0,1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月”):当地LcaseWeekDays [: toarray”星期四、星期五坐,太阳,星期一,星期二,星期三”):当地PcaseWeekDays [: toarray”星期四、星期五坐,太阳,星期一,星期二,星期三”):local UcaseWeekDays [:toarray "THU,FRI,SAT,SUN,MON,TUE,WED"] :local Fzerofill do={:return [:pick (100 + $1) 1 3]} :local gmtSg "+"; :if ($vgmt < 0) do={:set gmtSg "-"; :set vgmt ($vgmt * -1)} :local gmtHr [:pick [:totime $vgmt] 0 2] :local gmtMn [:pick [:totime $vgmt] 3 5] :local vdoff [:toarray "0,4,5,7,8,10"] :local MM [:pick $vdate ($vdoff->2) ($vdoff->3)] :local M [:tonum $MM] :if ($vdate ~ ".../../....") do={ :set vdoff [:toarray "7,11,1,3,4,6"] :set M ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2) :if ($M>12) do={:set M ($M - 12)} :set MM [:pick (100 + $M) 1 3] } :local yyyy [:pick $vdate ($vdoff->0) ($vdoff->1)] :local Leap "No-Leap" ; :if ((($yyyy - 1968) % 4) = 0) do={:set Leap "Leap"; :set ($prMntDays->1) -1; :set ($prMntDays->2) 30} :local mmm ($LcaseMnts->$M) :local Mmm ($PcaseMnts->$M) :local MMM ($UcaseMnts->$M) :local dd [:pick $vdate ($vdoff->4) ($vdoff->5)] :local d [:tonum $dd] ; :local totd ((($yyyy - 1970) * 365) + (($yyyy - 1968) / 4) + ($prMntDays->$M) + ($d - 1)) :local www ($LcaseWeekDays->($totd % 7)) :local Www ($PcaseWeekDays->($totd % 7)) :local WWW ($UcaseWeekDays->($totd % 7)) :local HH [:pick $vtime 0 2] :local H [:tonum $HH] :local hh ([:tonum $HH] % 12); :if ($hh = 0) do={:set hh 12}; :set hh [$Fzerofill $hh] :local h [:tonum $hh] :local a "A"; :if ([:tonum $HH] > 11) do={:set a "P"} :local aa "$a\4D" :local mm [:pick $vtime 3 5] :local m [:tonum $mm] :local ss [:pick $vtime 6 8] :local s [:tonum $ss] :local Z "$gmtSg$gmtHr:$gmtMn" :local Unix (((((($totd * 24) + $H) * 60) + $m) * 60) + $s - $vgmt) # :return "$yyyy-$MM-$dd\54$HH:$mm:$ss$Z $Www $Leap $Unix" :return $Unix } :global unixtodatetime do={ :local ux [:tonum $1] :local Fzerofill do={:return [:pick (100 + $1) 1 3]} :local prMntDays [:toarray "0,0,31,59,90,120,151,181,212,243,273,304,334"] :local vgmt [:tonum [/system clock get gmt-offset]]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)} :if ($vgmt < 0) do={:set vgmt ($vgmt * -1)} :local tzepoch ($ux + $vgmt) :if ($tzepoch < 0) do={:set tzepoch 0} ; # unsupported negative unix epoch :local yearStart (1970 + ($tzepoch / 31536000)) :local tmpbissex (($yearStart - 1968) / 4) ; :if ((($yearStart - 1968) % 4) = 0) do={:set ($prMntDays->1) -1 ; :set ($prMntDays->2) 30} :local tmpsec ($tzepoch % 31536000) :local tmpdays (($tmpsec / 86400) - $tmpbissex) :if (($tmpsec < (86400 * $tmpbissex)) and ((($yearStart - 1968) % 4) = 0)) do={ :set tmpbissex ($tmpbissex - 1) ; :set ($prMntDays->1) 0 ; :set ($prMntDays->2) 31 ; :set tmpdays ($tmpdays + 1) } :if ($tmpsec < (86400 * $tmpbissex)) do={:set yearStart ($yearStart - 1) ; :set tmpdays ($tmpdays + 365)} :local mnthStart 12 ; :while (($prMntDays->$mnthStart) > $tmpdays) do={:set mnthStart ($mnthStart - 1)} :local dayStart [$Fzerofill (($tmpdays + 1) - ($prMntDays->$mnthStart))] :local timeStart (00:00:00 + [:totime ($tmpsec % 86400)]) :return "$yearStart/$[$Fzerofill $mnthStart]/$[$Fzerofill $dayStart] $timeStart" } :global timetoseconds do={ :local inTime $1 :local wPos [:find $inTime "w" -1] :local dPos [:find $inTime "d" -1] :local itLen [:find $inTime "." -1] ; :if ([:typeof $itLen] = "nil") do={:set itLen [:len $inTime]} :local itSec [:pick $inTime ($itLen - 2) $itLen] :local itMin [:pick $inTime ($itLen - 5) ($itLen - 3)] :local itHou [:pick $inTime ($itLen - 8) ($itLen - 6)] :local itDay 0 :local itWee 0 :if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set itDay [:pick $inTime 0 $dPos] } :if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set itDay [:pick $inTime ($wPos + 1) $dPos] } :if ([:typeof $wPos] = "num") do={:set itWee [:pick $inTime 0 $wPos] } :local totitSec ($itSec + (60 * $itMin) + (3600 * $itHou) + (86400 * $itDay) + (604800 * $itWee)) :return $totitSec } :put "RouterBOARD is started $[$unixtodatetime ([$currdatetimestr] - [$timetoseconds [/system resource get uptime]])]"
:global currendatetimestr do={/系统时钟:本地vdate [get date]:本地vtime [get time]:本地VGMT [:tonum [get gmt-offset]];:如果($ vgmt > 0 x7fffffff) ={:设置vgmt ($ vgmt - 0 x100000000)}:当地prMntDays [: toarray”59岁,0,0,31日90120151181212243273304334”):当地LcaseMnts [: toarray“0,1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月”):当地PcaseMnts [: toarray“0,1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月”):当地UcaseMnts [: toarray“0,1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月”):当地LcaseWeekDays [: toarray”星期四、星期五坐,太阳,星期一,星期二,星期三”):当地PcaseWeekDays [: toarray”星期四、星期五坐,太阳,星期一,星期二,星期三”):local UcaseWeekDays [:toarray "THU,FRI,SAT,SUN,MON,TUE,WED"] :local Fzerofill do={:return [:pick (100 + $1) 1 3]} :local gmtSg "+"; :if ($vgmt < 0) do={:set gmtSg "-"; :set vgmt ($vgmt * -1)} :local gmtHr [:pick [:totime $vgmt] 0 2] :local gmtMn [:pick [:totime $vgmt] 3 5] :local vdoff [:toarray "0,4,5,7,8,10"] :local MM [:pick $vdate ($vdoff->2) ($vdoff->3)] :local M [:tonum $MM] :if ($vdate ~ ".../../....") do={ :set vdoff [:toarray "7,11,1,3,4,6"] :set M ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate ($vdoff->2) ($vdoff->3)] -1] / 2) :if ($M>12) do={:set M ($M - 12)} :set MM [:pick (100 + $M) 1 3] } :local yyyy [:pick $vdate ($vdoff->0) ($vdoff->1)] :local Leap "No-Leap" ; :if ((($yyyy - 1968) % 4) = 0) do={:set Leap "Leap"; :set ($prMntDays->1) -1; :set ($prMntDays->2) 30} :local mmm ($LcaseMnts->$M) :local Mmm ($PcaseMnts->$M) :local MMM ($UcaseMnts->$M) :local dd [:pick $vdate ($vdoff->4) ($vdoff->5)] :local d [:tonum $dd] ; :local totd ((($yyyy - 1970) * 365) + (($yyyy - 1968) / 4) + ($prMntDays->$M) + ($d - 1)) :local www ($LcaseWeekDays->($totd % 7)) :local Www ($PcaseWeekDays->($totd % 7)) :local WWW ($UcaseWeekDays->($totd % 7)) :local HH [:pick $vtime 0 2] :local H [:tonum $HH] :local hh ([:tonum $HH] % 12); :if ($hh = 0) do={:set hh 12}; :set hh [$Fzerofill $hh] :local h [:tonum $hh] :local a "A"; :if ([:tonum $HH] > 11) do={:set a "P"} :local aa "$a\4D" :local mm [:pick $vtime 3 5] :local m [:tonum $mm] :local ss [:pick $vtime 6 8] :local s [:tonum $ss] :local Z "$gmtSg$gmtHr:$gmtMn" :local Unix (((((($totd * 24) + $H) * 60) + $m) * 60) + $s - $vgmt) # :return "$yyyy-$MM-$dd\54$HH:$mm:$ss$Z $Www $Leap $Unix" :return $Unix } :global unixtodatetime do={ :local ux [:tonum $1] :local Fzerofill do={:return [:pick (100 + $1) 1 3]} :local prMntDays [:toarray "0,0,31,59,90,120,151,181,212,243,273,304,334"] :local vgmt [:tonum [/system clock get gmt-offset]]; :if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)} :if ($vgmt < 0) do={:set vgmt ($vgmt * -1)} :local tzepoch ($ux + $vgmt) :if ($tzepoch < 0) do={:set tzepoch 0} ; # unsupported negative unix epoch :local yearStart (1970 + ($tzepoch / 31536000)) :local tmpbissex (($yearStart - 1968) / 4) ; :if ((($yearStart - 1968) % 4) = 0) do={:set ($prMntDays->1) -1 ; :set ($prMntDays->2) 30} :local tmpsec ($tzepoch % 31536000) :local tmpdays (($tmpsec / 86400) - $tmpbissex) :if (($tmpsec < (86400 * $tmpbissex)) and ((($yearStart - 1968) % 4) = 0)) do={ :set tmpbissex ($tmpbissex - 1) ; :set ($prMntDays->1) 0 ; :set ($prMntDays->2) 31 ; :set tmpdays ($tmpdays + 1) } :if ($tmpsec < (86400 * $tmpbissex)) do={:set yearStart ($yearStart - 1) ; :set tmpdays ($tmpdays + 365)} :local mnthStart 12 ; :while (($prMntDays->$mnthStart) > $tmpdays) do={:set mnthStart ($mnthStart - 1)} :local dayStart [$Fzerofill (($tmpdays + 1) - ($prMntDays->$mnthStart))] :local timeStart (00:00:00 + [:totime ($tmpsec % 86400)]) # :return "$yearStart/$[$Fzerofill $mnthStart]/$[$Fzerofill $dayStart] $timeStart" :return "$[$Fzerofill $dayStart]/$[$Fzerofill $mnthStart]/$yearStart $timeStart" } :global timetoseconds do={ :local inTime $1 :local wPos [:find $inTime "w" -1] :local dPos [:find $inTime "d" -1] :local itLen [:find $inTime "." -1] ; :if ([:typeof $itLen] = "nil") do={:set itLen [:len $inTime]} :local itSec [:pick $inTime ($itLen - 2) $itLen] :local itMin [:pick $inTime ($itLen - 5) ($itLen - 3)] :local itHou [:pick $inTime ($itLen - 8) ($itLen - 6)] :local itDay 0 :local itWee 0 :if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set itDay [:pick $inTime 0 $dPos] } :if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set itDay [:pick $inTime ($wPos + 1) $dPos] } :if ([:typeof $wPos] = "num") do={:set itWee [:pick $inTime 0 $wPos] } :local totitSec ($itSec + (60 * $itMin) + (3600 * $itHou) + (86400 * $itDay) + (604800 * $itWee)) :return $totitSec } :put "RouterBOARD is started $[$unixtodatetime ([$currdatetimestr] - [$timetoseconds [/system resource get uptime]])]"
120年代:延迟
我重复一遍:好的,谢谢。
BR。
没什么,我们得等等,谢谢。我重复一遍:
到目前为止,我还没有编写一个函数来转换回unix epoch到日期和时间,但将来我会编写一个反向函数。
直到我完成该函数或我找到另一个URL,该函数提供正确的unix epoch的路由器板的开始时间,但不是正确的日期和时间。ios版雷竞技官网入口
:global unixtodatetime do={: local ux [:tonum $1]:local Fzerofill do={:return [:pick (100 + $1) 1 3]}:local prMntDays [:toarray "0,0,31,59,90,120,151,181,212,243,273,304,334"]:local vgmt [:tonum [/system clock get gmt-offset]];:if ($vgmt > 0x7FFFFFFF) do={:set vgmt ($vgmt - 0x100000000)}:if ($vgmt < 0) do={:set vgmt ($vgmt * -1)}:local tzpoch ($ux + $vgmt):if ($ tzpoch < 0) do={:set tzpoch 0};# unsupported negative unix epoch:local yearStart (1970 + ($ zepoch / 31536000)):local tmpbissex (($yearStart - 1968) / 4);:如果(((yearStart美元- 1968)% 4)= 0)做={:设置(prMntDays - > 1美元)1;:set ($prMntDays->2) 30}:local tmpsec ($tzepoch % 31536000):local tmpdays (($tmpsec / 86400) - $tmpbissex):if (($tmpsec < (86400 * $tmpbissex)) and ((($yearStart - 1968) % 4) = 0)) do={:set tmpbissex ($tmpbissex - 1);:set ($prMntDays->1) 0;:set ($prMntDays->2) 31;:set tmpdays ($tmpdays + 1)}:if ($tmpsec < (86400 * $tmpbissex)) do={:set yearStart ($yearStart - 1);:set tmpdays ($tmpdays + 365)}:local mnthStart 12;:while (($prMntDays->$mnthStart) >$ tmpdays) do={:set mnthStart ($mnthStart - 1)}:local dayStart [$Fzerofill (($tmpdays + 1) - ($prMntDays->$mnthStart))]:local timeStart (00:00:00 + [:totime ($tmpsec % 86400)]):return "$yearStart/$[$Fzerofill $mnthStart]/$[$Fzerofill $dayStart] $timeStart"}
:global timetoseconds do={:local inTime $1:local wPos [:find $inTime "w" -1]:local dPos [:find $inTime "d" -1]:local itLen [:find $inTime "."1);:如果([:typeof itLen美元]= nil)做={:设置itLen [: len亲密的美元]}:当地安全评估[:选择泰(itLen - 2美元)itLen美元):当地itMin[:选择亲密的美元($ itLen - 5) (itLen - 3)):当地itHou[:选择泰(itLen - 8美元)美元($ itLen - 6)]:当地itDay 0:当地itWee 0:如果(([:typeof wpo美元]= nil)和([:typeof dPos美元]=“num”))做={:设置itDay[:选择亲密的0 dPos美元]}:如果(([:typeof wpo美元]=“num”)和([:typeof dPos美元]=“num”))做={:设置itDay[:选择泰(wpo + 1美元)dPos美元]}:如果([:typeof wpo美元]=“num”)do={:set itWee [:pick $inTime 0 $wPos]}:local totitSec ($itSec + (60 * $itMin) + (3600 * $itHou) + (86400 * $itDay) + (604800 * $itWee))):return $totitSec}
:put [$timetoseconds [:timestamp]]
:put [$unixtodatetime [$timetoseconds [:timestamp]]]
完美的雷克斯!
(这个数值我已经提取并分配给一个局部变量)<时间> 546837 > < /运行时间
#使用[$sec2mdhms 59043245]输出:24mo.11d.8h.54m。增加了获取当前月份天数的代码片段,扩展为:global sec2mdhms do={#当前月份的天数:local mm [:pick [/system clock get date] 0 3];:本地yyyy[:选择[/系统时钟得到日期]7 11]:当地arrDaysOnMonths{1 =“31”;2月=“28”;3 =“31”;4月= " 30 ";5 =“31”;6月= " 30 ";7 =“31”;8月=“31”;9月= " 30 ";10月=“31”;11月= " 30 ";12月=“31”}:如果(((yyyy - 1972美元)% 4)= 0)做={:设置(arrDaysOnMonths美元- > 2月)29}:当地dd [: tonum (arrDaysOnMonths - >毫米)美元]:当地totalSeconds [: tonum $ 1]:当地莫(totalSeconds / 60美元/ 60美元/ 24 / dd):当地D (totalSeconds / 60美元/ 60/24 % $ dd):本地H (totalSeconds / 60/60 % 24美元):当地米(60 $ totalSeconds / 60%):本地(totalSeconds % 60美元):如果($莫> 0)={:返回(“$莫”“莫”。”。”。“D”美元。“D”。”。”。“H”美元。“H”。”。”。“M”美元。“M”。”。”。“$ S”。“S”)}:如果($ D > 0) ={:返回(“$ D”“D”。”。”。“H”美元。“H”。”。”。“M”美元。“M”。”。”。“$ S”。“S”)}:如果(H > 0美元)={:返回(“H”美元“H”。”。”。“M”美元。“M”。”。”。“$ S”。“S”)}:如果(M > 0美元)={:返回(“$ M”“M”。”。”。“$ S”。“S”)}:如果(S > 0美元)={:返回(“S”美元。“S”)}}
当前月份的天数,通过扩展:本地mm [:pick [/system clock get date] 0 3];:本地yyyy[:选择[/系统时钟得到日期]7 11]:当地arrDaysOnMonths{1 =“31”;2月=“28”;3 =“31”;4月= " 30 ";5 =“31”;6月= " 30 ";7 =“31”;8月=“31”;9月= " 30 ";10月=“31”;11月= " 30 ";12月=“31”}:如果(((yyyy - 1972美元)% 4)= 0)做={:设置(arrDaysOnMonths美元- > 2月)29}:当地dd [: tonum (arrDaysOnMonths - >毫米)美元]
再见rextended,
今天我带来了一个新的挑战,我想转换我想控制的远程设备的正常运行时间图,该值以秒为单位的细节(我认为):
(这个数值我已经提取并分配给一个局部变量)<时间> 546837 > < /运行时间
{:local read "546837 ":put [:totime [:pick $read ([:find $read ">" -1] + 1) [:find $read "" -1]]]}
6 d07:53:57
正常运行时间是一个绝对值,必须不考虑闰年或时区,
是CPU启动的秒数,与任何其他传统的日期和时间表示方式无关。
无论是秒还是像97w4d08:54:05这样的文本。
这也是为什么写97w4d08:54:05而不像1y10m3w4d08:54:05,因为月份和年份不是单一的。
{:global tokenParser:global unixtodatetime:global currdatetimestr:local xmlData ([toarray [/tool fetch mode=https url="http://192.168.8.1/api/device/information" as-value output=user]] ->"data"):local smsUptime [($tokenParser->"getTag") source=$xmlData tag="uptime"];# uptime value例如:618694:put [$unixtodatetime ([$currdatetimestr] - $smsUptime)]} Result: 03/02/2023 09:40:27(日期格式我已经修改为我的内部使用)
不是我的选择,而是逻辑的选择,以逻辑的方式表示日期和时间:左边是更高的值,就像数字一样。结果:03/02/2023 09:40:27
(日期格式我已经修改,供我内部使用)
嗨@rextended !搜索标签#延长在线正常运行时间开始日期时间
只有在RouterBOARD时间同步的情况下才ios版雷竞技官网入口能正常工作。
:put [$unixtodatetime ([$currdatetimestr] - [$timetoseconds[/系统资源获取正常运行时间]])]
:if ($tmpsec < (86400 * $tmpbissex)) do={:set yearStart ($yearStart - 1):set tmpdays ($tmpdays + 365)}计算年数时,若未经过已过的六分之一日数,仍为上一年度…
:local mnthStart 12;:while (($prMntDays->$mnthStart) >= tmpdays) do={:set mnthStart ($mnthStart - 1)}因为不存在月日“0”,所以必须上上个月。
多亏了你。脚本工作良好,现在,谢谢!