Timestamp functions
#1

Hi all,

i despair with timestamps, i canґt find any solution for my problem.
Maybe you can help me

So I want to write 2 functions:

TimestampToDate(timestamp,&day,&week,&year,&second ,&minute,&hour)

RemainingTimeToTimestamp(timestamp,&RemDays,&RemWe eks,&RemYears,&RemSeconds,&RemMinutes,&RemHours)*

*This function means, if i have a timestamp maybe

1320320036 (03.11.2011 12:33:56)

and

1320320063 (03.11.2011 12:34:23)

So it returns 0days 0weeks 0years 27seconds 0minutes 0hours

etc.


Please help me,

I dont know how to write the functions, i spend a lot of time of searching posted functions but they donґt meet my wishes.

Cody09
Reply
#2

These functions can be made in PAWN but as ****** said, all sorts of timezone/time calculations all around the world are very complex. That's why I suggest you refer to using the CTime library if you're looking to format for example.

pawn Код:
new tm <tmTime>, string[64];
localtime(Time:timestamp, tmTime);
strftime(string, sizeof(string), "%A %d %B %Y %H", tmTime);
printf("Output: %s", string);
To get the difference between 2 timestamps, you could create your own function. What it needs to do is calculate the difference in seconds (timestamps themselves) and then something like this:
pawn Код:
new difference = timestamp2 - timestamp1,
    days, hours, minutes;
while(difference >= 86400)
{
    difference -= 86400;
    days ++;
}
while(difference >= 3600)
{
    difference -= 3600;
    hours ++;
}
while(difference >= 60)
{
    difference -= 60;
    minutes ++;
}
seconds = difference;
Reply
#3

hm ok, thank you
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)