22.07.2017, 19:00
Hello guys, I have problem with my clock. My host is in another country and the time there is different. I need to add 1 hour 3 minutes and 16 seconds to fix it. How can I add to my clock? Can you give me.
new string[256],year,month,day,hours,minutes,seconds; getdate(year, month, day), gettime(hours, minutes, seconds); format(string, sizeof string, "%d/%s%d/%s%d", day, ((month < 10) ? ("0") : ("")), month, (year < 10) ? ("0") : (""), year); TextDrawSetString(Date, string); format(string, sizeof string, "%s%d:%s%d:%s%d", (hours < 10) ? ("0") : (""), hours, (minutes < 10) ? ("0") : (""), minutes, (seconds < 10) ? ("0") : (""), seconds); TextDrawSetString(Time, string); |
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)));
}
This should work ** /me copies others with their emoji **:
PHP код:
|