summaryrefslogtreecommitdiff
path: root/Userland/date.cpp
blob: d280a7434f9c3f3c6f8345d1751e6bbd474ffaaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <time.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char** argv)
{
    time_t now = time(nullptr);

    if (argc == 2 && !strcmp(argv[1], "-u")) {
        printf("%u\n", now);
        return 0;
    }

    auto* tm = localtime(&now);
    printf("%4u-%02u-%02u %02u:%02u:%02u\n",
        tm->tm_year + 1900,
        tm->tm_mon + 1,
        tm->tm_mday,
        tm->tm_hour,
        tm->tm_min,
        tm->tm_sec);
    return 0;
}