This is a function used to generate random ports, because the day in different time zones around the world will be the most different for one day, then the client machine calculates today, yesterday, tomorrow, they can get the same random port as the server through the corresponding encrypted computing, and the server listens to all the ports generated from yesterday, today, and tomorrow.
Time_t time (time_t * timer );
If you have already declared the timer parameter, you can return the current calendar time from the timer parameter, or return the current calendar time from a time point (for example: january 1, 1970 00:00:00) the number of seconds until now. If the parameter is null (NUL), the function returns the current calendar time only by returning the value. For example, the following example shows the current calendar time:
In this way, we can use the returned value time_t to determine the number of yesterday and the number of tomorrow. Of course, it is easy to find the number of today and the number of next hour, you only need to subtract the corresponding number of seconds from the return value of time (), and then use the localtime () function to obtain the desired data.
Void find3day ()
{
Struct TM * local;
Time_t t = time (null );
Cout <"seconds:" <t <Endl;
Local = localtime (& T );
Int day = Local-> tm_mday;
Cout <"today is:" <day <Endl;
T = t-86400; // 86400 is the number of seconds per day
Local = localtime (& T );
Day = Local-> tm_mday;
Cout <"yesterday:" <day <Endl;
T = T + 172800; // 172800 is the number of seconds in 2 days
Local = localtime (& T );
Day = Local-> tm_mday;
Cout <"Tomorrow is:" <day <Endl;
Return;
}