| 1 |
<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="systemd.time"> |
| 7 |
|
| 8 |
<refentryinfo> |
| 9 |
<title>systemd.time</title> |
| 10 |
<productname>systemd</productname> |
| 11 |
</refentryinfo> |
| 12 |
|
| 13 |
<refmeta> |
| 14 |
<refentrytitle>systemd.time</refentrytitle> |
| 15 |
<manvolnum>7</manvolnum> |
| 16 |
</refmeta> |
| 17 |
|
| 18 |
<refnamediv> |
| 19 |
<refname>systemd.time</refname> |
| 20 |
<refpurpose>Time and date specifications</refpurpose> |
| 21 |
</refnamediv> |
| 22 |
|
| 23 |
<refsect1> |
| 24 |
<title>Description</title> |
| 25 |
|
| 26 |
<para>In systemd, timestamps, time spans, and calendar events are |
| 27 |
displayed and may be specified in closely related syntaxes.</para> |
| 28 |
</refsect1> |
| 29 |
|
| 30 |
<refsect1> |
| 31 |
<title>Displaying Time Spans</title> |
| 32 |
|
| 33 |
<para>Time spans refer to time durations. On display, systemd will present time spans as a space-separated series |
| 34 |
of time values each suffixed by a time unit. Example:</para> |
| 35 |
|
| 36 |
<programlisting>2h 30min</programlisting> |
| 37 |
|
| 38 |
<para>All specified time values are meant to be added up. The above hence refers to 150 minutes. Display is |
| 39 |
locale-independent, only English names for the time units are used.</para> |
| 40 |
</refsect1> |
| 41 |
|
| 42 |
<refsect1> |
| 43 |
<title>Parsing Time Spans</title> |
| 44 |
|
| 45 |
<para>When parsing, systemd will accept the same time span syntax. |
| 46 |
Separating spaces may be omitted. The following time units are |
| 47 |
understood:</para> |
| 48 |
|
| 49 |
<itemizedlist> |
| 50 |
<listitem><para>usec, us, μs</para></listitem> |
| 51 |
<listitem><para>msec, ms</para></listitem> |
| 52 |
<listitem><para>seconds, second, sec, s</para></listitem> |
| 53 |
<listitem><para>minutes, minute, min, m</para></listitem> |
| 54 |
<listitem><para>hours, hour, hr, h</para></listitem> |
| 55 |
<listitem><para>days, day, d</para></listitem> |
| 56 |
<listitem><para>weeks, week, w</para></listitem> |
| 57 |
<listitem><para>months, month, M (defined as 30.44 days)</para></listitem> |
| 58 |
<listitem><para>years, year, y (defined as 365.25 days)</para></listitem> |
| 59 |
</itemizedlist> |
| 60 |
|
| 61 |
<para>If no time unit is specified, generally seconds are assumed, but some exceptions exist and are marked as |
| 62 |
such. In a few cases <literal>ns</literal>, <literal>nsec</literal> is accepted too, where the granularity of the |
| 63 |
time span permits this. Parsing is generally locale-independent, non-English names for the time units are not |
| 64 |
accepted.</para> |
| 65 |
|
| 66 |
<para>Examples for valid time span specifications:</para> |
| 67 |
|
| 68 |
<programlisting>2 h |
| 69 |
2hours |
| 70 |
48hr |
| 71 |
1y 12month |
| 72 |
55s500ms |
| 73 |
300ms20s 5day</programlisting> |
| 74 |
|
| 75 |
<para>One can use the <command>timespan</command> command of |
| 76 |
<citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 77 |
to normalise a textual time span for testing and validation purposes.</para> |
| 78 |
|
| 79 |
<para>Internally, systemd generally operates with microsecond time granularity, while the default time |
| 80 |
unit in user-configurable time spans is usually seconds (see above). This disparity becomes visible when |
| 81 |
comparing the same settings in the (high-level) unit file syntax with the matching (more low-level) D-Bus |
| 82 |
properties (which are what |
| 83 |
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>'s |
| 84 |
<command>show</command> command displays). The former typically are suffixed with <literal>…Sec</literal> |
| 85 |
to indicate the default unit of seconds, the latter are typically suffixed with <literal>…USec</literal> |
| 86 |
to indicate the underlying low-level time unit, even if they both encapsulate the very same |
| 87 |
settings.</para> |
| 88 |
</refsect1> |
| 89 |
|
| 90 |
<refsect1> |
| 91 |
<title>Displaying Timestamps</title> |
| 92 |
|
| 93 |
<para>Timestamps refer to specific, unique points in time. On |
| 94 |
display, systemd will format these in the local timezone as |
| 95 |
follows:</para> |
| 96 |
|
| 97 |
<programlisting>Fri 2012-11-23 23:02:15 CET</programlisting> |
| 98 |
|
| 99 |
<para>The weekday is printed in the abbreviated English language form. The formatting is locale-independent.</para> |
| 100 |
|
| 101 |
<para>In some cases timestamps are shown in the UTC timezone instead of the local timezone, which is indicated via |
| 102 |
the <literal>UTC</literal> timezone specifier in the output.</para> |
| 103 |
|
| 104 |
<para>In some cases timestamps are shown with microsecond granularity. In this case, the sub-second remainder is |
| 105 |
separated by a full stop from the seconds component.</para> |
| 106 |
</refsect1> |
| 107 |
|
| 108 |
<refsect1> |
| 109 |
<title>Parsing Timestamps</title> |
| 110 |
|
| 111 |
<para>When parsing, systemd will accept a similar syntax, but some fields can be omitted, |
| 112 |
and the space between the date and time can be replaced with a <literal>T</literal> |
| 113 |
(à la the <ulink url="https://tools.ietf.org/html/rfc3339">RFC 3339</ulink> profile of ISO 8601); |
| 114 |
thus, in CET, the following are all identical: |
| 115 |
<literal>Fri 2012-11-23 23:02:15 CET</literal>, |
| 116 |
<literal>Fri 2012-11-23T23:02:15</literal>, |
| 117 |
<literal>2012-11-23T23:02:15 CET</literal>, |
| 118 |
<literal>2012-11-23 23:02:15</literal>.</para> |
| 119 |
|
| 120 |
<para>The timezone defaults to the current timezone if not specified explicitly. |
| 121 |
It may be given after a space, like above, in which case it can be: |
| 122 |
<literal>UTC</literal>, |
| 123 |
an entry in the installed IANA timezone database (e.g. <literal>CET</literal>, <literal>Asia/Tokyo</literal>, |
| 124 |
where the complete list can be obtained with <command>timedatectl list-timezones</command> (see |
| 125 |
<citerefentry><refentrytitle>timedatectl</refentrytitle><manvolnum>1</manvolnum></citerefentry>)), |
| 126 |
or <literal>±<replaceable>05</replaceable></literal>, |
| 127 |
<literal>±<replaceable>05</replaceable><replaceable>30</replaceable></literal>, |
| 128 |
<literal>±<replaceable>05</replaceable>:<replaceable>30</replaceable></literal>, |
| 129 |
<literal>Z</literal>.</para> <!-- glibc %z --> |
| 130 |
|
| 131 |
<para>It may also be affixed directly to the timestamp, in which case it must correspond |
| 132 |
to one of the formats defined in the |
| 133 |
<ulink url="https://tools.ietf.org/html/rfc3339">RFC 3339</ulink> profile of ISO 8601: |
| 134 |
<literal>±<replaceable>05</replaceable>:<replaceable>30</replaceable></literal> or <literal>Z</literal>. |
| 135 |
Thus, the following are also identical to the above: |
| 136 |
<literal>2012-11-23T23:02:15+01:00</literal>, |
| 137 |
<literal>2012-11-23 22:02:15Z</literal>.</para> |
| 138 |
|
| 139 |
<para>A timestamp can start with a field containing a weekday, which can be in an abbreviated |
| 140 |
(<literal>Wed</literal>) or non-abbreviated (<literal>Wednesday</literal>) English language form (case |
| 141 |
does not matter), regardless of the locale. |
| 142 |
However, if a weekday <emphasis>is</emphasis> specified and does not match the date, the timestamp is rejected.</para> |
| 143 |
|
| 144 |
<para>If the date is omitted, it defaults to today. If the time is omitted, it defaults to 00:00:00. |
| 145 |
Fractional seconds can be specified down to 1µs precision. The seconds field can also be omitted, defaulting to 0.</para> |
| 146 |
|
| 147 |
<para>There are special tokens that can be used in place of timestamps: |
| 148 |
<literal>now</literal> may be |
| 149 |
used to refer to the current time (or of the invocation of the |
| 150 |
command that is currently executed). <literal>today</literal>, |
| 151 |
<literal>yesterday</literal>, and <literal>tomorrow</literal> refer to |
| 152 |
00:00:00 of the current day, the day before, or the next day, |
| 153 |
respectively.</para> |
| 154 |
|
| 155 |
<para>Relative times are also accepted: a time span (see above) prefixed with |
| 156 |
<literal>+</literal> is evaluated to the current time plus the |
| 157 |
specified time span. Correspondingly, a time span that is prefixed |
| 158 |
with <literal>-</literal> is evaluated to the current time minus |
| 159 |
the specified time span. Instead of prefixing the time span with |
| 160 |
<literal>+</literal> or <literal>-</literal>, it may also be |
| 161 |
suffixed with a space and the word <literal>left</literal> or |
| 162 |
<literal>ago</literal>.</para> |
| 163 |
|
| 164 |
<para>Finally, an integer prefixed with <literal>@</literal> is |
| 165 |
evaluated relative to the UNIX epoch – 1970-01-01 00:00:00 UTC.</para> |
| 166 |
|
| 167 |
<para>Examples for valid timestamps and their normalized form (assuming the current time was 2012-11-23 |
| 168 |
18:15:22 and the timezone was UTC+8, for example <literal>TZ=:Asia/Shanghai</literal>):</para> |
| 169 |
|
| 170 |
<programlisting> Fri 2012-11-23 11:12:13 → Fri 2012-11-23 11:12:13 |
| 171 |
2012-11-23 11:12:13 → Fri 2012-11-23 11:12:13 |
| 172 |
2012-11-23 11:12:13 UTC → Fri 2012-11-23 19:12:13 |
| 173 |
2012-11-23T11:12:13Z → Fri 2012-11-23 19:12:13 |
| 174 |
2012-11-23T11:12+02:00 → Fri 2012-11-23 17:12:00 |
| 175 |
2012-11-23 → Fri 2012-11-23 00:00:00 |
| 176 |
12-11-23 → Fri 2012-11-23 00:00:00 |
| 177 |
11:12:13 → Fri 2012-11-23 11:12:13 |
| 178 |
11:12 → Fri 2012-11-23 11:12:00 |
| 179 |
now → Fri 2012-11-23 18:15:22 |
| 180 |
today → Fri 2012-11-23 00:00:00 |
| 181 |
today UTC → Fri 2012-11-23 16:00:00 |
| 182 |
yesterday → Fri 2012-11-22 00:00:00 |
| 183 |
tomorrow → Fri 2012-11-24 00:00:00 |
| 184 |
tomorrow Pacific/Auckland → Thu 2012-11-23 19:00:00 |
| 185 |
+3h30min → Fri 2012-11-23 21:45:22 |
| 186 |
-5s → Fri 2012-11-23 18:15:17 |
| 187 |
11min ago → Fri 2012-11-23 18:04:22 |
| 188 |
@1395716396 → Tue 2014-03-25 03:59:56</programlisting> |
| 189 |
|
| 190 |
<para>Note that timestamps displayed by remote systems with a non-matching timezone are usually not parsable |
| 191 |
locally, as the timezone component is not understood (unless it happens to be <literal>UTC</literal>).</para> |
| 192 |
|
| 193 |
<para>Timestamps may also be specified with microsecond granularity. The sub-second remainder is expected separated |
| 194 |
by a full stop from the seconds component. Example:</para> |
| 195 |
|
| 196 |
<programlisting>2014-03-25 03:59:56.654563</programlisting> |
| 197 |
|
| 198 |
<para>In some cases, systemd will display a relative timestamp (relative to the current time, or the time of |
| 199 |
invocation of the command) instead of or in addition to an absolute timestamp as described above. A relative |
| 200 |
timestamp is formatted as follows:</para> |
| 201 |
|
| 202 |
<programlisting>2 months 5 days ago</programlisting> |
| 203 |
|
| 204 |
<para>Note that a relative timestamp is also accepted where a timestamp is expected (see above).</para> |
| 205 |
|
| 206 |
<para>Use the <command>timestamp</command> command of |
| 207 |
<citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry> to |
| 208 |
validate and normalize timestamps for testing purposes.</para> |
| 209 |
</refsect1> |
| 210 |
|
| 211 |
<refsect1> |
| 212 |
<title>Calendar Events</title> |
| 213 |
|
| 214 |
<para>Calendar events may be used to refer to one or more points |
| 215 |
in time in a single expression. They form a superset of the |
| 216 |
absolute timestamps explained above:</para> |
| 217 |
|
| 218 |
<programlisting>Thu,Fri 2012-*-1,5 11:12:13</programlisting> |
| 219 |
|
| 220 |
<para>The above refers to 11:12:13 of the first or fifth day of |
| 221 |
any month of the year 2012, but only if that day is a Thursday or |
| 222 |
Friday.</para> |
| 223 |
|
| 224 |
<para>The weekday specification is optional. If specified, it |
| 225 |
should consist of one or more English language weekday names, |
| 226 |
either in the abbreviated (Wed) or non-abbreviated (Wednesday) |
| 227 |
form (case does not matter), separated by commas. Specifying two |
| 228 |
weekdays separated by <literal>..</literal> refers to a range of |
| 229 |
continuous weekdays. <literal>,</literal> and <literal>..</literal> |
| 230 |
may be combined freely.</para> |
| 231 |
|
| 232 |
<para>In the date and time specifications, any component may be specified as <literal>*</literal> in |
| 233 |
which case any value will match. Alternatively, each component can be specified as a list of values |
| 234 |
separated by commas. Values may be suffixed with <literal>/</literal> and a repetition value, which |
| 235 |
indicates that the value itself and the value plus all multiples of the repetition value are matched. |
| 236 |
Two values separated by <literal>..</literal> may be used to indicate a range of values; ranges may also |
| 237 |
be followed with <literal>/</literal> and a repetition value, in which case the expression matches all |
| 238 |
times starting with the start value, and continuing with all multiples of the repetition value relative |
| 239 |
to the start value, ending at the end value the latest.</para> |
| 240 |
|
| 241 |
<para>A date specification may use <literal>~</literal> to indicate the last day in a month. For example, |
| 242 |
<literal>*-02~03</literal> means "the third last day in February," and <literal>Mon *-05~07/1</literal> |
| 243 |
means "the last Monday in May."</para> |
| 244 |
|
| 245 |
<para>The seconds component may contain decimal fractions both in |
| 246 |
the value and the repetition. All fractions are rounded to 6 |
| 247 |
decimal places.</para> |
| 248 |
|
| 249 |
<para>Either time or date specification may be omitted, in which |
| 250 |
case 00:00:00 and *-*-* is implied, respectively. If the |
| 251 |
seconds component is not specified, <literal>:00</literal> is |
| 252 |
assumed.</para> |
| 253 |
|
| 254 |
<para>Timezone can be specified as the literal string <literal>UTC</literal>, or |
| 255 |
the local timezone, similar to the supported syntax of timestamps (see above), or the timezone |
| 256 |
in the IANA timezone database format (also see above).</para> |
| 257 |
|
| 258 |
<para>The following special expressions may be used as shorthands for longer normalized forms:</para> |
| 259 |
|
| 260 |
<programlisting> minutely → *-*-* *:*:00 |
| 261 |
hourly → *-*-* *:00:00 |
| 262 |
daily → *-*-* 00:00:00 |
| 263 |
monthly → *-*-01 00:00:00 |
| 264 |
weekly → Mon *-*-* 00:00:00 |
| 265 |
yearly → *-01-01 00:00:00 |
| 266 |
quarterly → *-01,04,07,10-01 00:00:00 |
| 267 |
semiannually → *-01,07-01 00:00:00 |
| 268 |
</programlisting> |
| 269 |
|
| 270 |
<para>Examples for valid timestamps and their |
| 271 |
normalized form:</para> |
| 272 |
|
| 273 |
<programlisting> Sat,Thu,Mon..Wed,Sat..Sun → Mon..Thu,Sat,Sun *-*-* 00:00:00 |
| 274 |
Mon,Sun 12-*-* 2,1:23 → Mon,Sun 2012-*-* 01,02:23:00 |
| 275 |
Wed *-1 → Wed *-*-01 00:00:00 |
| 276 |
Wed..Wed,Wed *-1 → Wed *-*-01 00:00:00 |
| 277 |
Wed, 17:48 → Wed *-*-* 17:48:00 |
| 278 |
Wed..Sat,Tue 12-10-15 1:2:3 → Tue..Sat 2012-10-15 01:02:03 |
| 279 |
*-*-7 0:0:0 → *-*-07 00:00:00 |
| 280 |
10-15 → *-10-15 00:00:00 |
| 281 |
monday *-12-* 17:00 → Mon *-12-* 17:00:00 |
| 282 |
Mon,Fri *-*-3,1,2 *:30:45 → Mon,Fri *-*-01,02,03 *:30:45 |
| 283 |
12,14,13,12:20,10,30 → *-*-* 12,13,14:10,20,30:00 |
| 284 |
12..14:10,20,30 → *-*-* 12..14:10,20,30:00 |
| 285 |
mon,fri *-1/2-1,3 *:30:45 → Mon,Fri *-01/2-01,03 *:30:45 |
| 286 |
03-05 08:05:40 → *-03-05 08:05:40 |
| 287 |
08:05:40 → *-*-* 08:05:40 |
| 288 |
05:40 → *-*-* 05:40:00 |
| 289 |
Sat,Sun 12-05 08:05:40 → Sat,Sun *-12-05 08:05:40 |
| 290 |
Sat,Sun 08:05:40 → Sat,Sun *-*-* 08:05:40 |
| 291 |
2003-03-05 05:40 → 2003-03-05 05:40:00 |
| 292 |
05:40:23.4200004/3.1700005 → *-*-* 05:40:23.420000/3.170001 |
| 293 |
2003-02..04-05 → 2003-02..04-05 00:00:00 |
| 294 |
2003-03-05 05:40 UTC → 2003-03-05 05:40:00 UTC |
| 295 |
2003-03-05 → 2003-03-05 00:00:00 |
| 296 |
03-05 → *-03-05 00:00:00 |
| 297 |
hourly → *-*-* *:00:00 |
| 298 |
daily → *-*-* 00:00:00 |
| 299 |
daily UTC → *-*-* 00:00:00 UTC |
| 300 |
monthly → *-*-01 00:00:00 |
| 301 |
weekly → Mon *-*-* 00:00:00 |
| 302 |
weekly Pacific/Auckland → Mon *-*-* 00:00:00 Pacific/Auckland |
| 303 |
yearly → *-01-01 00:00:00 |
| 304 |
annually → *-01-01 00:00:00 |
| 305 |
*:2/3 → *-*-* *:02/3:00</programlisting> |
| 306 |
|
| 307 |
<para>Calendar events are used by timer units, see |
| 308 |
<citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 309 |
for details.</para> |
| 310 |
|
| 311 |
<para>Use the <command>calendar</command> command of |
| 312 |
<citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry> to validate |
| 313 |
and normalize calendar time specifications for testing purposes. The tool also calculates when a specified |
| 314 |
calendar event would occur next.</para> |
| 315 |
</refsect1> |
| 316 |
|
| 317 |
<refsect1> |
| 318 |
<title>See Also</title> |
| 319 |
<para><simplelist type="inline"> |
| 320 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 321 |
<member><citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 322 |
<member><citerefentry><refentrytitle>systemd.timer</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 323 |
<member><citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 324 |
<member><citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 325 |
<member><citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 326 |
</simplelist></para> |
| 327 |
</refsect1> |
| 328 |
|
| 329 |
</refentry> |