--- /dev/null
+DATE(1)
+## NAME
+*date* - display the current time and date
+## SYNOPSIS
+*date* \[-u\]
+## DESCRIPTION
+The *date* command displays the current date and time. If the *-u* option is
+specified the time and date are shown in UTC, otherwise they are shown in
+local time.
+## STANDARDS
+The *date* command is from POSIX 1003.1P. Fuzix does not currently implement
+custom formats or system time setting via date.
#include <time.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-int main(int argc, char *argv[])
+static void usage(void)
{
- time_t now;
- const char *p;
+ write(2, "date: [-u]\n", 11);
+ exit(EXIT_FAILURE);
+}
- now = time(NULL);
- p = ctime(&now);
- write(1, p, strlen(p));
+int main(int argc, char *argv[])
+{
+ time_t t;
+ struct tm *tm;
+ const char *ts, *z;
+ int utc = 0;
+
+ if (argc > 1 && strcmp(argv[1], "-u") == 0) {
+ utc = 1;
+ argc--;
+ }
+ if (argc != 1)
+ usage();
+ time(&t);
+ if (utc)
+ tm = gmtime(&t);
+ else
+ tm = localtime(&t);
+ ts = asctime(tm);
+ /* Up to the time zone */
+ write(1, ts, 20);
+ /* Zone */
+ z = tzname[tm->tm_isdst];
+ write(1, z, strlen(z));
+ /* Year */
+ write(1, ts + 19, 6);
return 0;
}