Thread: [Solved] Time Format
View Single Post
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-04-2019 , 16:10   Re: Time Format
Reply With Quote #5

Quote:
Originally Posted by Natsheh View Post
g_iRoundTime += g_Current_timestamp.......
No, that won't work in this case.

Quote:
Originally Posted by Gabe Iggy View Post
Hello.

Sadly, format_time() accepts a unix timestamp as a parameter, while I'm using seconds remaning in g_iRoundTime.
The idea was that you would format only the time (and not the date) and I assumed that your values wouldn't ever exceed 24 hours. In that case, it should work just fine. However, I just tested it and I realized that it gets the time/date from your PC which will take into account the timezone. If it used GMT always, it would work just fine.

Now, if you subtract the timezone offset, it works the way I was suggesting. However, subtracting the timezone offset will only work if you are west of the GMT. If you are east of the GMT you'd need to also add 24 hours.

The only other obstacle is accounting for daylights savings which actually shifts your timezone offset.


So, this works for me:

PHP Code:
public cmdTest()
{
    new 
szArg[100], iArg
    read_args
(szArgcharsmax(szArg))
    
remove_quotes(szArg)
    
iArg str_to_num(szArg)
    
    new 
iGMTOffset_h = -// GMT-06:00
    
    
new szTime[100]
    
format_time(szTimecharsmax(szTime), "%H:%M:%S"iArg 3600*iGMTOffset_h)
    
server_print(szTime)


However, it's going to be better to write a new function to do this:

PHP Code:
public relative_time_string(szTimeString[], leniSeconds)
{
    
formatex(szTimeStringlen"%02d:%02d:%02d"iSeconds 3600, (iSeconds 3600) / 60iSeconds 60)

__________________

Last edited by fysiks; 05-04-2019 at 16:11.
fysiks is offline