get-date.c 284 B

12345678910111213
  1. /*
  2. Prints the current date as YYYYMMDD
  3. e.g. 2024-12-25
  4. */
  5. #include <stdio.h>
  6. #include <time.h>
  7. int main(int arg_count, char const **arg_ptr) {
  8. time_t t = time(NULL);
  9. struct tm* now = localtime(&t);
  10. printf("%04d-%02d-%02d", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday);
  11. }