Raised This Month: $7 Target: $400
 1% 

Solved Time Format


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 05-04-2019 , 01:24   Time Format
Reply With Quote #1

Hello

I'm using get_time_length() to display a time remaining hud message.
Code:
new hud[125] get_time_length(iPlayers[i], g_iRoundTime, timeunit_seconds, hud, charsmax(hud));

But it gets formated like this:


Is there anyway to use the HH:MM:SS format?

EDIT: Fixed it by borrowing the code from another plugin.

Code:
new hud[125] new m = g_iRoundTime/60 new h = m/60 new s = g_iRoundTime-m*60 m = m-h*60 if(h)     formatex(hud,charsmax(hud),"%d:%02d:%02d",h,m,s) else     formatex(hud,charsmax(hud),"%d:%02d",m,s)
__________________

Last edited by gabuch2; 05-05-2019 at 14:22.
gabuch2 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-04-2019 , 02:35   Re: Time Format
Reply With Quote #2

Try format_time() from amxmodx.inc.
__________________
fysiks is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 05-04-2019 , 13:04   Re: Time Format
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Try format_time() from amxmodx.inc.
Hello.

Sadly, format_time() accepts a unix timestamp as a parameter, while I'm using seconds remaning in g_iRoundTime.
__________________

Last edited by gabuch2; 05-04-2019 at 13:04.
gabuch2 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-04-2019 , 13:07   Re: Time Format
Reply With Quote #4

g_iRoundTime += g_Current_timestamp.......
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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
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 02:56.


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