datetime.c 333 B

1234567891011121314151617181920
  1. /* See LICENSE file for copyright and license details. */
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include "../util.h"
  5. const char *
  6. datetime(const char *fmt)
  7. {
  8. time_t t;
  9. t = time(NULL);
  10. if (!strftime(buf, sizeof(buf), fmt, localtime(&t))) {
  11. warn("strftime: Result string exceeds buffer size");
  12. return NULL;
  13. }
  14. return buf;
  15. }