-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate-and-time
98 lines (76 loc) · 3.45 KB
/
date-and-time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# By rextended.
# https://forum.mikrotik.com/viewforum.php?f=9
###################
# Version simpler #
###################
:global simplercurrdatetimestr do={
/system clock
:local vdate [get date]
:local vtime [get time]
:local yyyy [:pick $vdate 7 11]
:local M ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate 1 3] -1] / 2); :if ($M>12) do={:set M ($M - 12)}
:local MM [:pick (100 + $M) 1 3]
:local dd [:pick $vdate 4 6]
:local HH [:pick $vtime 0 2]
:local mm [:pick $vtime 3 5]
:local ss [:pick $vtime 6 8]
:return "$dd-$MM-$yyyy $HH:$mm:$ss"
}
:put [$simplercurrdatetimestr]
################
# Version full #
################
:global currdatetimestr do={
/system clock
:local vdate [get date]
:local vtime [get time]
:local vgmt [:tonum [get gmt-offset]]; :if ($vgmt > 86400) do={:set vgmt ($vgmt - 4294967296)}
:local LcaseMnts [:toarray "0,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"]
:local PcaseMnts [:toarray "0,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"]
:local UcaseMnts [:toarray "0,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC"]
:local Fzerofill do={:return [:pick (100 + $1) 1 3]}
:local gmtSg "+"; :if ($vgmt < 0) do={:set gmtSg "-"; :set vgmt ($vgmt * -1)}
:local gmtHr [$Fzerofill ($vgmt / 3600)]
:local gmtMn [$Fzerofill (($vgmt % 3600) / 60)]
:local yyyy [:pick $vdate 7 11]
:local M ([:find "xxanebarprayunulugepctovecANEBARPRAYUNULUGEPCTOVEC" [:pick $vdate 1 3] -1] / 2); :if ($M>12) do={:set M ($M - 12)}
:local MM [$Fzerofill $M]
:local Mmm ($LcaseMnts->$M)
:local MMm ($PcaseMnts->$M)
:local MMM ($UcaseMnts->$M)
:local dd [:pick $vdate 4 6]
:local d [:tonum $dd]
: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"
:return "$yyyy-$MM-$dd\54$HH:$mm:$ss$Z"
}
:put [$currdatetimestr]
# Comments version full
$yyyy current year full number ex. 2022
$MM current month number with 0 ex. 01,02,03...10,11,12
$M current month number without 0 ex. 1,2,3...10,11,12
$MMM current short month name UPPERCASE JAN,FEB...NOV,DIC
$MMm current short month name Propercase Jan,Feb...Nov,Dic (not standard)
$Mmm current short month name lowercase jan,feb...nov,dic (not standard)
$dd current day number with 0 ex. 01,02,03...29,30,31
$d current day number without 0 ex. 1,2,3...29,30,31
$HH current hour number 24h format with 0 ex. 00,01,02...21,22,23
$H current hour number 24h format without 0 ex. 0,1,2...21,22,23
$hh current hour number 12h format with 0 ex. 01,02,03...10,11,12
$h current hour number 12h format without 0 ex. 1,2,3...10,11,12
$aa current AM / PM symbol for 12h format ex. AM or PM
$a current first letter only of AM / PM symbol for 12h format ex. A or P
$mm current minute number with 0 ex. 00,01,02...57,58,59
$m current minute number without 0 ex. 0,1,2...57,58,59
$ss current second number with 0 ex. 00,01,02...57,58,59(,60?)
$s current second number without 0 ex. 0,1,2...57,58,59(,60?)
$Z current Time Zone offset ex. -23:59...+00:00...+23:59