2011-03-30 12:46:40 +00:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
|
2012-09-02 11:08:14 +00:00
|
|
|
int uflg, nflg, iflg, tflg;
|
2011-03-30 12:46:40 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ulong now;
|
2012-09-02 11:08:14 +00:00
|
|
|
Tm *tm;
|
2011-03-30 12:46:40 +00:00
|
|
|
ARGBEGIN{
|
|
|
|
case 'n': nflg = 1; break;
|
|
|
|
case 'u': uflg = 1; break;
|
2012-09-02 11:08:14 +00:00
|
|
|
case 't': tflg = 1; /* implies -i */
|
|
|
|
case 'i': iflg = 1; break;
|
|
|
|
default: fprint(2, "usage: date [-itun] [seconds]\n"); exits("usage");
|
2011-03-30 12:46:40 +00:00
|
|
|
}ARGEND
|
|
|
|
|
|
|
|
if(argc == 1)
|
|
|
|
now = strtoul(*argv, 0, 0);
|
|
|
|
else
|
|
|
|
now = time(0);
|
|
|
|
|
|
|
|
if(nflg)
|
|
|
|
print("%ld\n", now);
|
2012-09-02 11:08:14 +00:00
|
|
|
else if(iflg) {
|
|
|
|
tm = uflg ? gmtime(now) : localtime(now);
|
|
|
|
if(tflg)
|
|
|
|
print("%s\n", isotime(tm));
|
|
|
|
else
|
|
|
|
print("%s\n", isodate(tm));
|
|
|
|
} else {
|
|
|
|
if(uflg)
|
|
|
|
print("%s", asctime(gmtime(now)));
|
|
|
|
else
|
|
|
|
print("%s", ctime(now));
|
|
|
|
}
|
2011-03-30 12:46:40 +00:00
|
|
|
exits(0);
|
|
|
|
}
|