summaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorJ William Piggott2016-02-17 01:28:36 +0100
committerJ William Piggott2016-02-17 01:37:32 +0100
commite05ac5aae00913e7a999c96a7bb731dc1d09cc5c (patch)
tree2360a2d8a2f8f653619dbc895f8e5272a26179d2 /sys-utils
parentMerge branch 'wrap_padding' of https://github.com/ignatenkobrain/util-linux (diff)
downloadkernel-qcow2-util-linux-e05ac5aae00913e7a999c96a7bb731dc1d09cc5c.tar.gz
kernel-qcow2-util-linux-e05ac5aae00913e7a999c96a7bb731dc1d09cc5c.tar.xz
kernel-qcow2-util-linux-e05ac5aae00913e7a999c96a7bb731dc1d09cc5c.zip
hwclock.c, hwclock.8.in: new --show format
* hwclock.c: change --get and --show functions to the ISO 8601 format and concatenate fractional seconds to the time display. * hwclock.8.in: document this. Signed-off-by: J William Piggott <elseifthen@gmx.com>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/hwclock.8.in8
-rw-r--r--sys-utils/hwclock.c17
2 files changed, 12 insertions, 13 deletions
diff --git a/sys-utils/hwclock.8.in b/sys-utils/hwclock.8.in
index d72b7a8ee..eddb8647f 100644
--- a/sys-utils/hwclock.8.in
+++ b/sys-utils/hwclock.8.in
@@ -88,16 +88,14 @@ command, such as \%'11\ minute\ mode' or from dual-booting another OS.
.TQ
.B \-\-get
.br
-Read the Hardware Clock and print the time on standard output.
+Read the Hardware Clock and print its time to standard output in the
+.B ISO 8601
+format.
The time shown is always in local time, even if you keep your Hardware Clock
in UTC. See the
.B \%\-\-localtime
option.
.sp
-The time shown is in same format as that of
-.BR \%date (1)
-by default, and additionally, the number of microseconds is shown.
-.sp
Showing the Hardware Clock time is the default when no function is specified.
.sp
The
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index f50739b50..21e0d1b6a 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -687,14 +687,15 @@ display_time(const bool hclock_valid, struct timeval hwctime)
"either invalid (e.g. 50th day of month) or beyond the range "
"we can handle (e.g. Year 2095)."));
else {
- struct tm *lt;
- char *format = "%c";
- char ctime_now[200];
-
- lt = localtime(&hwctime.tv_sec);
- strftime(ctime_now, sizeof(ctime_now), format, lt);
- printf(_("%s and %06ld microseconds\n"),
- ctime_now, (long)hwctime.tv_usec);
+ struct tm lt;
+ int zhour, zmin;
+
+ lt = *localtime(&hwctime.tv_sec);
+ zhour = - timezone / 60 / 60;
+ zmin = abs(timezone / 60 % 60);
+ printf(_("%4d-%.2d-%.2d %02d:%02d:%02d.%06ld%+02d:%02d\n"),
+ lt.tm_year + 1900, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour,
+ lt.tm_min, lt.tm_sec, (long)hwctime.tv_usec, zhour, zmin);
}
}