Raised This Month: $ Target: $400
 0% 

Getting Current time?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ShadowMarioBR
Member
Join Date: Feb 2018
Old 08-24-2018 , 23:01   Getting Current time?
Reply With Quote #1

Is there anyway to get current time in a format of HH-MM-SS?
That's for a "Get time when a specific player join" plugin (using Database stuff).

Excuse my bad english.
ShadowMarioBR is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 08-25-2018 , 00:39   Re: Getting Current time?
Reply With Quote #2

http://pubs.opengroup.org/onlinepubs.../strftime.html

PHP Code:
char sTime[32];
FormatTime(sTimesizeof(sTime), "%I-%M-%S"GetTime()); 
__________________
Psyk0tik is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-25-2018 , 06:38   Re: Getting Current time?
Reply With Quote #3

If you are using database, store the GetTime() as int and not as char (FormatTime()).
Ilusion9 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-25-2018 , 06:43   Re: Getting Current time?
Reply With Quote #4

With MySQL you can just set a column to NOW().

DATE_FORMAT will also help.
__________________
Neuro Toxin is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-25-2018 , 12:40   Re: Getting Current time?
Reply With Quote #5

@Neuro Toxin

I would do what Ilusion9 said. GetTime is going to be the best alternative, since it doesn't require you to fetch the data, it's already built in.

Btw, DATE_FORMAT and NOW() returns the date 'n the time.
I'd say CURRENT_TIME for this case.
mug1wara is offline
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 08-26-2018 , 06:15   Re: Getting Current time?
Reply With Quote #6

GetTime() return the the time since the server starter right?
What if I want the actual world time with GMT/UTC in parameter maybe, is there a function for that?
__________________
My Steam I take private requests if related with TF2
My Plugins
Facksy is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-26-2018 , 06:29   Re: Getting Current time?
Reply With Quote #7

Quote:
Originally Posted by Facksy View Post
GetTime() return the the time since the server starter right?
What if I want the actual world time with GMT/UTC in parameter maybe, is there a function for that?
https://sm.alliedmods.net/new-api/sourcemod/GetTime
Ilusion9 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-26-2018 , 06:34   Re: Getting Current time?
Reply With Quote #8

Quote:
Originally Posted by Facksy View Post
GetTime() return the the time since the server starter right?
What if I want the actual world time with GMT/UTC in parameter maybe, is there a function for that?
GetTime() returns the local time of where ever the server is located.

Now, for the timezone part I would use this inc.

PHP Code:
#include <sourcemod>
#include <unixtime_sourcemod>

#pragma semicolon 1

public void OnPluginStart()
{
    
// Some timezones. Bigger list can be found in the .inc file.
    
    /*
        UT_TIMEZONE_CST
        UT_TIMEZONE_CET
        UT_TIMEZONE_EET
        UT_TIMEZONE_PST
        UT_TIMEZONE_EST
        UT_TIMEZONE_WET
    */
    
    
int iYeariMonthiDayiHouriMinuteiSecond;
    
    
UnixToTime(GetTime(), iYeariMonthiDayiHouriMinuteiSecondUT_TIMEZONE_CST);
    
    
PrintToServer("%02d:%02d"iHouriMinute);


Last edited by mug1wara; 08-26-2018 at 06:34.
mug1wara is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-26-2018 , 10:24   Re: Getting Current time?
Reply With Quote #9

Quote:
Originally Posted by mug1wara View Post
GetTime() returns the local time of where ever the server is located.
UNIX timestamps (which is what GetTime returns) are the number of seconds since 1970-01-01 00:00:00 UTC, it should be the same regardless of what time zone the server is in.

FormatTime, on the other hand, converts that to the server's time zone...
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 08-26-2018 at 10:25.
Powerlord is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-26-2018 , 14:01   Re: Getting Current time?
Reply With Quote #10

Quote:
Originally Posted by Powerlord View Post
UNIX timestamps (which is what GetTime returns) are the number of seconds since 1970-01-01 00:00:00 UTC, it should be the same regardless of what time zone the server is in.

FormatTime, on the other hand, converts that to the server's time zone...
Right.
mug1wara is offline
Reply



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 14:07.


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