date.c 659 B

1234567891011121314151617181920212223242526272829
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2022, 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  4. * Copyright (C) 2022 Leah Rowe <leah@libreboot.org>
  5. */
  6. #include <time.h>
  7. #include <stdio.h>
  8. #include <errno.h>
  9. #define REQ_ERRPRINT
  10. #include "../common/common.h"
  11. int main(int argc, char *argv[]) {
  12. time_t epoch = time(NULL);
  13. struct tm* date = localtime(&epoch);
  14. char date_s[31];
  15. const char *format;
  16. if (argc == 2 && argv[1][0] == '+') {
  17. argv[1]++;
  18. format = argv[1];
  19. }
  20. else {
  21. format = "%a %b %e %H:%M:%S %Z %Y";
  22. }
  23. strftime(date_s, 31, format, date);
  24. printf("%s\n", date_s);
  25. return errprint(argv[0], NULL, errno);
  26. }