Yesterday, Today, tomorrow

Source: Internet
Author: User
Tags time zones

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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.