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

Solved How to convert date to UNIX (timestamp) time?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fastmancz
Senior Member
Join Date: Jul 2013
Location: Czech Republic
Old 12-15-2017 , 18:31   How to convert date to UNIX (timestamp) time?
Reply With Quote #1

Hello,

how do I convert my time format to a Unix timestamp?

PHP Code:
    int timestamp GetTime();
    
char timestamp_porovnam[250], timestamp_porovnam2[250];
    
FormatTime(timestamp_porovnamsizeof(timestamp_porovnam), "%d.%m.%Y %H:%M:%S"timestamp); //Here everything is all right
    
FormatTime(timestamp_porovnam2sizeof(timestamp_porovnam2), "%d.%m.%Y 08:00:00"timestamp); //Here everything is all right
    
int timestamp_porovnam_converted StringToInt(timestamp_porovnam); //I get the value of 16
    
int timestamp_porovnam_converted2 StringToInt(timestamp_porovnam2); //I get the value of 16

    
if(timestamp_porovnam_converted timestamp_porovnam_converted2)
    {
        
PrintToServer("off");
    }
    else
    {
        
PrintToServer("on");
    } 
Thank you for your answers.
__________________


Main owner of the CMGPORTAL.CZ.
---------------------------------------
My plugins:
[CS:GO] Panorama - Timeleft
[CS:GO] JailBreak - Be quiet, please!

Last edited by Fastmancz; 12-16-2017 at 07:27.
Fastmancz is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 12-15-2017 , 18:54   Re: How to convert date to UNIX (timestamp) time?
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=84689
__________________
8guawong is offline
Fastmancz
Senior Member
Join Date: Jul 2013
Location: Czech Republic
Old 12-15-2017 , 19:08   Re: How to convert date to UNIX (timestamp) time?
Reply With Quote #3

Thanks for your answer. How should I write it? I need a simple thing. Is the current time smaller than 8:00 AM? I need to make this a condition. Thanks for help.
__________________


Main owner of the CMGPORTAL.CZ.
---------------------------------------
My plugins:
[CS:GO] Panorama - Timeleft
[CS:GO] JailBreak - Be quiet, please!
Fastmancz is offline
brunoronning
Senior Member
Join Date: Jan 2014
Location: Brazil
Old 12-15-2017 , 19:41   Re: How to convert date to UNIX (timestamp) time?
Reply With Quote #4

https://forums.alliedmods.net/showthread.php?t=300350
brunoronning is offline
Fastmancz
Senior Member
Join Date: Jul 2013
Location: Czech Republic
Old 12-16-2017 , 05:17   Re: How to convert date to UNIX (timestamp) time?
Reply With Quote #5

How can I do that?
__________________


Main owner of the CMGPORTAL.CZ.
---------------------------------------
My plugins:
[CS:GO] Panorama - Timeleft
[CS:GO] JailBreak - Be quiet, please!
Fastmancz is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 12-16-2017 , 05:58   Re: How to convert date to UNIX (timestamp) time?
Reply With Quote #6

Quote:
Originally Posted by Fastmancz View Post
How can I do that?
use the include provided in the link above your post
__________________
8guawong is offline
Fastmancz
Senior Member
Join Date: Jul 2013
Location: Czech Republic
Old 12-16-2017 , 07:25   Re: How to convert date to UNIX (timestamp) time?
Reply With Quote #7

Done.
https://forums.alliedmods.net/showthread.php?t=300350

PHP Code:
#include <unixtime_sourcemod>

int iTime1iTimeAdjusted1iYear1iMonth1iDay1iHour1iMinute1iSecond1;
int iTime2iTimeAdjusted2iYear2iMonth2iDay2iHour2iMinute2iSecond2;

public 
void OnClientPutInServer(int client)
{
    
iTime1 GetTime( );
    
UnixToTimeiTime1 iYear1 iMonth1 iDay1 iHour1 iMinute1 iSecond1 );
    
iHour1 iHour1+1//Added hour due to time zone
    
iTimeAdjusted1 TimeToUnixiYear1 iMonth1 iDay1 iHour1 iMinute1 iSecond1 );
    
PrintToServer("----> %d"iTimeAdjusted1); //Current time

    
iTime2 GetTime( );
    
UnixToTimeiTime2 iYear2 iMonth2 iDay2 iHour2 iMinute2 iSecond2 );
    
iHour2 8;
    
iMinute2 0;
    
iSecond2 0;
    
iTimeAdjusted2 TimeToUnixiYear2 iMonth2 iDay2 iHour2 iMinute2 iSecond2 );
    
PrintToServer("----> %d"iTimeAdjusted2); //Changed Time - Hours (08:00)
}

    if(
iTimeAdjusted1 iTimeAdjusted2)
    {
        
PrintToServer("off");
    }
    else
    {
        
PrintToServer("on");
    } 
__________________


Main owner of the CMGPORTAL.CZ.
---------------------------------------
My plugins:
[CS:GO] Panorama - Timeleft
[CS:GO] JailBreak - Be quiet, please!

Last edited by Fastmancz; 12-16-2017 at 07:26.
Fastmancz 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 09:55.


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