Raised This Month: $12 Target: $400
 3% 

[INC] Unix Time


Post New Thread Reply   
 
Thread Tools Display Modes
rak
Veteran Member
Join Date: Oct 2011
Location: banned country
Old 08-24-2012 , 12:45   Re: [INC] Unix Time
Reply With Quote #11

bugsy, in TimeToUnix dont should be..

original
Code:
stock TimeToUnix( const iYear , const iMonth , const iDay , const iHour , const iMinute , const iSecond , TimeZones:tzTimeZone=UT_TIMEZONE_UTC) {     new i , iTimeStamp;     for ( i = 1970 ; i < iYear ; i++ )         iTimeStamp += YearSeconds[ IsLeapYear(i) ];     for ( i = 1 ; i < iMonth ; i++ )         iTimeStamp += SecondsInMonth( iYear , i );     iTimeStamp += ( ( iDay - 1 ) * DaySeconds );     iTimeStamp += ( iHour * HourSeconds );     iTimeStamp += ( iMinute * MinuteSeconds );     iTimeStamp += iSecond;     if ( tzTimeZone == UT_TIMEZONE_SERVER )         tzTimeZone = GetTimeZone();             return ( iTimeStamp + TimeZoneOffset[ tzTimeZone ] ); }

Code:
stock TimeToUnix( const iYear , const iMonth , const iDay , const iHour , const iMinute , const iSecond , TimeZones:tzTimeZone=UT_TIMEZONE_UTC) {     new i , iTimeStamp;     for ( i = 1970 ; i < iYear ; i++ )         iTimeStamp += YearSeconds[ IsLeapYear(i) ];     for ( i = 1 ; i < iMonth ; i++ )         iTimeStamp += SecondsInMonth( iYear , i );     iTimeStamp += ( ( iDay - 1 ) * DaySeconds );     iTimeStamp += ( iHour * HourSeconds );     iTimeStamp += ( iMinute * MinuteSeconds );     iTimeStamp += iSecond;     if ( tzTimeZone == UT_TIMEZONE_SERVER )         tzTimeZone = GetTimeZone();        
    return ( iTimeStamp - TimeZoneOffset[ tzTimeZone ] );
}

test with original
Spoiler

with my change
Spoiler
__________________

www.amxmodx-es.com

Steam: Luchokoldo

Last edited by rak; 08-24-2012 at 12:47.
rak is offline
Send a message via MSN to rak Send a message via Skype™ to rak
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-24-2012 , 19:49   Re: [INC] Unix Time
Reply With Quote #12

Refer to this site to see the time-zone offsets. I used 01/01/2000 at 00:00:00 for easy math.

This will print out time for all time-zone offsets
PHP Code:
Test()
{
    new 
iTime iYear iMonth iDay iHour iMinute iSecond;

    for ( new 
TimeZones:tzZone UT_TIMEZONE_MIT tzZone TimeZones tzZone++ )
    {
        
iTime TimeToUnix2000 tzZone );
        
UnixToTimeiTime iYear iMonth iDay iHour iMinute iSecond );
        
        
server_print"%02d/%02d/%02d %02d:%02d:%02d" iMonth iDay iYear iHour iMinute iSecond );
    }

Output UT_TIMEZONE_MIT -> UT_TIMEZONE_NZDT, respectively
Spoiler

Time-zone offsets from the above link
Spoiler
__________________

Last edited by Bugsy; 08-24-2012 at 19:52.
Bugsy is offline
rak
Veteran Member
Join Date: Oct 2011
Location: banned country
Old 08-25-2012 , 02:29   Re: [INC] Unix Time
Reply With Quote #13

bugsy, look, i use your .inc to make a task in a specific date.. if i use the stock without my change, this give me bad result

look my code
PHP Code:
public _register_task_date(iPluginiParams) {
    
    new 
iTime TimeToUnix(get_param(1), get_param(2), get_param(3), get_param(4), get_param(5), get_param(6), UT_TIMEZONE_SERVER)
    
    new 
SysTime get_systime()
    
    
server_print("iTime=%d || SysTime=%d || Diference=%d"iTimeSysTime, (iTime-SysTime))
    
    if((
SysTime get_timeleft()) < iTime)
        return -
1
    
    
if((iTime iTime SysTime) <= 0)
        return -
2

    entity_set_float
(g_EntEV_FL_nextthinkfloat(iTime))

    return 
1

EDIT:

I found the diference.. it's from get_systime..
PHP Code:
get_systime() 

PHP Code:
get_systime(TimeZoneOffset[GetTimeZone()]) 
sorry bugsy
__________________

www.amxmodx-es.com

Steam: Luchokoldo

Last edited by rak; 08-25-2012 at 03:12.
rak is offline
Send a message via MSN to rak Send a message via Skype™ to rak
V I R U S
Senior Member
Join Date: Jul 2004
Location: Russia / Germany
Old 09-28-2012 , 19:45   Re: [INC] Unix Time
Reply With Quote #14

Thanks, very useful.
__________________
V I R U S is offline
Send a message via ICQ to V I R U S
waza123a
Member
Join Date: Mar 2010
Old 04-07-2015 , 11:32   Re: [INC] Unix Time
Reply With Quote #15

thanks very useful, from php.
__________________
Life is good, sometimes...
waza123a is offline
Mikka
Member
Join Date: Dec 2018
Old 07-09-2022 , 14:03   Re: [INC] Unix Time
Reply With Quote #16

Hello, how to use this include if i have in string (07-09-2022 20:15:00)?
playerDate[id][date] < --- date from mysql include to.
Mikka is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-09-2022 , 15:57   Re: [INC] Unix Time
Reply With Quote #17

Quote:
Originally Posted by Mikka View Post
Hello, how to use this include if i have in string (07-09-2022 20:15:00)?
playerDate[id][date] < --- date from mysql include to.
This include doesn't work with strings so you need to parse the string to extract the various values and then pass them to TimeToUnix().
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode