PHP код:
main()
{
printf("%s", GetDateAndTime());
printf("%s", GetDateAndTime(3796)); // 3796 seconds = 1 hour, 3 minutes and 16 seconds
}
GetDateAndTime(second_diff = 0)
{
new string[21], year, month, day, hour, minute, second;
getdate(year, month, day), gettime(hour, minute, second);
second += second_diff;
while(second >= 60)
{
second -= 60;
minute += 1;
if(minute >= 60)
{
minute -= 60;
hour += 1;
if(hour >= 24)
{
hour -= 24;
switch(month)
{
case 1, 3, 5, 7, 8, 10, 12: // January, March, May, July, August, October and December
{
if(day < 31)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
case 2: // February
{
if(IsLeapYear(year))
{
if(day < 29)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
else
{
if(day < 28)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
}
case 4, 6, 9, 11: // April, June, September and November
{
if(day < 30)
{
day ++;
}
else
{
day = 1;
month ++;
}
}
}
if(month > 12)
{
month = 1;
year ++;
}
}
}
}
format(string, sizeof(string), "%02d-%02d-%04d, %02d:%02d:%02d", month, day, year, hour, minute, second);
return string;
}
IsLeapYear(year)
{
return (((!(year % 4)) && (year % 100)) || (!(year % 400)));
}