Two string (time) compare and calculate how much time passed
#1

Heelloo every1!

I have been trying to make a script, witch calculates how much time passed since player last logged in.
So, I have this datetime script I made, 1min = 5005ms

As the minutes goes when reaches 60, hour goes plus, but minutes resets. And so on. The same goes with days, months, years.

It is pretty simple, as you can see,
I am not goot at maths, so when I am trying to make this script, it makes a lot of trouble.

Firstly I looked all over the internet about these time things and their calculations. Also, tried to understand in PHP, witch made more sense, but when I got to pawn and started to understand a lot of different script, I really fucked up my brain.

So, found this script made by Y-Less, called mktime. I would be grateful if someone could explain me, how exactly this script works and much love if could help, together make that - time passed since - scrpt.

Thankyou!

PS: the script by y-less
PHP Code:
mktime(hour,minute,second,day,month,year)
{
    new 
timestamp2;
    
timestamp2 second + (minute 60) + (hour 3600);
    new 
days_of_month[12];
    if ( ((
year == 0) && (year 100 != 0)) || (year 400 == 0) ) {
            
days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
        
} else {
            
days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
        
}
    new 
days_this_year 0;
    
days_this_year day;
    if(
month 1) { // No January Calculation, because its always the 0 past months
        
for(new i=0i<month-1;i++) {
            
days_this_year += days_of_month[i];
        }
    }
    
timestamp2 += days_this_year 86400;
    for(new 
j=1970;j<year;j++) {
        
timestamp2 += 31536000;
        if ( ((
year == 0) && (year 100 != 0)) || (year 400 == 0) )  timestamp2 += 86400// Schaltjahr + 1 Tag
    
}
    return 
timestamp2;

Reply


Messages In This Thread
Two string (time) compare and calculate how much time passed - by thaKing - 10.03.2017, 09:01
Re: Two string (time) compare and calculate how much time passed - by thaKing - 10.03.2017, 09:14
Re: Two string (time) compare and calculate how much time passed - by Toroi - 10.03.2017, 09:14

Forum Jump:


Users browsing this thread: 2 Guest(s)