AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|
05-07-2009
, 11:21
[INC] Unix Time
|
#1
|
Unix Time .: Description
This include contains two functions that allow you to convert unix time to normal time and vice versa.
Unix time on wiki: http://en.wikipedia.org/wiki/Unix_time
Timezone info: http://www.epochconverter.com/epoch/timezones.php
.: Commands- UnixToTime - This will convert unix time to normal time.
- TimeToUnix - This will convert normal time to unix time.
.: Usage- UnixToTime( iUnixTime , &iYear , &iMonth , &iDay , &iHour , &iMinute , &iSecond , [ TimeZone ] )
- iUnixTime - Unix time value to be converted to normal time.
- iYear .. iSecond - Normal time values passed by-reference.
- [ TimeZone ] - Optional parameter to obtain time values adjusted for a particular timezone. By default, UTC time is returned which has no timezone adjustment (same as what get_systime() returns). You can pass a timezone of your choice or use UT_TIMEZONE_SERVER to use the timezone of the server machine.
- TimeToUnix( iYear , iMonth , iDay , iHour , iMinute , iSecond , [ TimeZone ] )
- iYear .. iSecond - Normal time values to be converted to unix time.
- [ TimeZone ] - Optional parameter to obtain time values adjusted for a particular timezone. By default, UTC time is returned which has no timezone adjustment (same as what get_systime() returns). You can pass a timezone of your choice or use UT_TIMEZONE_SERVER to use the timezone of the server machine.
Comments: This include can be useful for working with timestamps or any task involving time\date manipulation. When using a timezone offset, only use it on a UTC (0 offset) time value. Specifying a timezone on a time value that is already offsetted will provide inaccurate results.
.: Example Code
PHP Code:
public UnixTime() { new iTime , iTimeAdjusted , iYear , iMonth , iDay , iHour , iMinute , iSecond; iTime = get_systime(); //Display get_systime() value which is UTC time (no +/- adjustment for timezone) server_print( "get_systime() = %d" , iTime ); UnixToTime( iTime , iYear , iMonth , iDay , iHour , iMinute , iSecond ); server_print( "get_systime() Time = %02d/%02d/%d %02d:%02d:%02d" , iMonth , iDay , iYear , iHour , iMinute , iSecond ); //Display time value adjusted with TimeToUnix() iTimeAdjusted = TimeToUnix( iYear , iMonth , iDay , iHour , iMinute , iSecond , UT_TIMEZONE_SERVER ); UnixToTime( iTimeAdjusted , iYear , iMonth , iDay , iHour , iMinute , iSecond ); server_print( "TimeToUnix Adjusted Time = %02d/%02d/%d %02d:%02d:%02d" , iMonth , iDay , iYear , iHour , iMinute , iSecond ); //Display time value adjusted with UnixToTime() UnixToTime( iTime , iYear , iMonth , iDay , iHour , iMinute , iSecond , UT_TIMEZONE_SERVER ); server_print( "UnixToTime Adjusted Time = %02d/%02d/%d %02d:%02d:%02d" , iMonth , iDay , iYear , iHour , iMinute , iSecond ); }
.: Changelog- v0.3
- Added optional parameter for specifying a timezone.
- v0.2
- Added reset to 0 of hour variable in UnixToTime function. This was only causing an issue if the hour variable was holding a value when passed into UnixToTime (since it is passed by reference). [thx stupok]
- v0.1
__________________
Last edited by Bugsy; 09-24-2011 at 16:34.
|
|