Add -i and -t options to date for isodate and isotime display.
This commit is contained in:
parent
cdb7bdde96
commit
dfc348c4e2
2 changed files with 23 additions and 8 deletions
|
@ -24,6 +24,12 @@ Report Greenwich Mean Time (GMT) rather than local time.
|
||||||
.B -n
|
.B -n
|
||||||
Report the date as the number of seconds since the
|
Report the date as the number of seconds since the
|
||||||
epoch, 00:00:00 GMT, January 1, 1970.
|
epoch, 00:00:00 GMT, January 1, 1970.
|
||||||
|
.TP
|
||||||
|
.B -i
|
||||||
|
Report the date as ISO-8601 without time and timezone suffix.
|
||||||
|
.TP
|
||||||
|
.B -t
|
||||||
|
Report the date as ISO-8601 with time and timezone suffix.
|
||||||
.PP
|
.PP
|
||||||
The conversion from Greenwich Mean Time to local time depends on the
|
The conversion from Greenwich Mean Time to local time depends on the
|
||||||
.B $timezone
|
.B $timezone
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
|
||||||
int uflg, nflg;
|
int uflg, nflg, iflg, tflg;
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
ulong now;
|
ulong now;
|
||||||
|
Tm *tm;
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'n': nflg = 1; break;
|
case 'n': nflg = 1; break;
|
||||||
case 'u': uflg = 1; break;
|
case 'u': uflg = 1; break;
|
||||||
default: fprint(2, "usage: date [-un] [seconds]\n"); exits("usage");
|
case 't': tflg = 1; /* implies -i */
|
||||||
|
case 'i': iflg = 1; break;
|
||||||
|
default: fprint(2, "usage: date [-itun] [seconds]\n"); exits("usage");
|
||||||
}ARGEND
|
}ARGEND
|
||||||
|
|
||||||
if(argc == 1)
|
if(argc == 1)
|
||||||
|
@ -21,10 +23,17 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if(nflg)
|
if(nflg)
|
||||||
print("%ld\n", now);
|
print("%ld\n", now);
|
||||||
else if(uflg)
|
else if(iflg) {
|
||||||
print("%s", asctime(gmtime(now)));
|
tm = uflg ? gmtime(now) : localtime(now);
|
||||||
else
|
if(tflg)
|
||||||
print("%s", ctime(now));
|
print("%s\n", isotime(tm));
|
||||||
|
else
|
||||||
|
print("%s\n", isodate(tm));
|
||||||
|
} else {
|
||||||
|
if(uflg)
|
||||||
|
print("%s", asctime(gmtime(now)));
|
||||||
|
else
|
||||||
|
print("%s", ctime(now));
|
||||||
|
}
|
||||||
exits(0);
|
exits(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue