Advertisement
Aslai

Unix time to human readable

Feb 18th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. int main(){
  2.     int months[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
  3.                      31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
  4.                      31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
  5.                      31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  6.     int time = 1330492354;
  7.     int days = time / (60*60*24);
  8.     time %= (60*60*24);
  9.     int hours = time / (60*60);
  10.     time %= (60*60);
  11.     int minutes = time / (60);
  12.     time %= (60);
  13.     int seconds = time;
  14.  
  15.     int years = 1970;
  16.     int i, d2 = days;
  17.  
  18.     for( i = 0; d2 > months[i%48]; ++i ){
  19.         d2 -= months[i%48];
  20.     }
  21.     years += i / 12;
  22.     int month = i % 12;
  23.     char* monthstr[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  24.     printf(" The date provided is %s %i, %i, and the time is %i:%i.%i\n", monthstr[month], d2+1, years, hours, minutes, seconds );
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement