bunkum

an old and silly c99 web server with some fun features
Log | Files | Refs | README

time.c (501B)


      1 #include <stdio.h>
      2 
      3 #include "time.h"
      4 
      5 const char* days[] = {
      6   "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
      7 };
      8 const char* months[] = {
      9   "Jan", "Feb", "Mar", "Apr", "May", "Jun",
     10   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
     11 };
     12 
     13 void time_to_str(time_t t, char* buf) {
     14     struct tm* gmt = gmtime(&t);
     15     sprintf(buf, "%s, %02d %s %d %02d:%02d:%02d GMT",
     16             days[gmt->tm_wday], gmt->tm_mday, months[gmt->tm_mon],
     17             gmt->tm_year + 1900, gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
     18 }