Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
716 B

6 years ago
6 years ago
  1. #include "fmt.h"
  2. #include "byte.h"
  3. #include <time.h>
  4. static unsigned int fmt_2digits(char* dest,int i) {
  5. dest[0]=(char)((i/10)+'0');
  6. dest[1]=(char)((i%10)+'0');
  7. return 2;
  8. }
  9. size_t fmt_iso8601(char* dest,time_t t) {
  10. struct tm* x=gmtime(&t);
  11. size_t i;
  12. if (dest==0) return sizeof("2014-05-27T19:22:16Z")-1;
  13. /* "2014-05-27T19:22:16Z" */
  14. i=fmt_ulong(dest,(x->tm_year+1900));
  15. dest[i++]='-';
  16. i+=fmt_2digits(dest+i,x->tm_mon+1);
  17. dest[i++]='-';
  18. i+=fmt_2digits(dest+i,x->tm_mday);
  19. dest[i++]='T';
  20. i+=fmt_2digits(dest+i,x->tm_hour);
  21. i+=fmt_str(dest+i,":");
  22. i+=fmt_2digits(dest+i,x->tm_min);
  23. i+=fmt_str(dest+i,":");
  24. i+=fmt_2digits(dest+i,x->tm_sec);
  25. i+=fmt_str(dest+i,"Z");
  26. return i;
  27. }