#include const int daysInMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int main () { int dd, mm, yyyy, h, m, s, i; int nsecs, ndays; printf("Enter system time in seconds : "); scanf("%d", &nsecs); yyyy = 1970; dd = nsecs / 86400; while (1) { ndays = (yyyy % 4 == 0) ? 366 : 365; if (dd >= ndays) { ++yyyy; dd -= ndays; } else { break; } } for (i=1; i<=12; ++i) { ndays = daysInMonth[i-1]; if ((i == 2) && (yyyy % 4 == 0)) ++ndays; if (dd < ndays) { mm = i; ++dd; break;} else dd -= ndays; } s = nsecs % 86400; h = s / 3600; s %= 3600; m = s / 60; s %= 60; printf("Time (dd-mm-yyyy hh:mm:ss) is %s%d-%s%d-%d %s%d:%s%d:%s%d\n", (dd < 10) ? "0" : "", dd, (mm < 10) ? "0" : "", mm, yyyy, (h < 10) ? "0" : "", h, (m < 10) ? "0" : "", m, (s < 10) ? "0" : "", s); }