datetime.c 358 B

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