WINAPI use: Time, Thread, interrupt

Source: Internet
Author: User
Tags local time month name

(1): C + + Get current system time:http://www.cnblogs.com/mfryf/archive/2012/02/13/2349360.html

However, when the calculation algorithm time is time-consuming, do not forget second, can not only use milliseconds to reduce, otherwise negative, if the algorithm takes too long to use the minutes. Otherwise, hours ...

Scenario-Benefits: Only use C standard library; Disadvantage: only accurate to second level
#include <time.h>
#include <stdio.h>
Int> Char tmp[64];
Strftime (TMP, sizeof (TMP), "%y/%m/%d%x%A%j Days of the Year",%z (localtime));
Puts (TMP);
return 0;
}
size_t strftime (char *strdest, size_t maxsize, const char *format, const struct TM *timeptr);
Generates a string from a format string.
struct TM *localtime (const time_t *timer);
Obtain local time, the results obtained by the localtime are returned by the structure TM
The returned string can be determined in the following format:
%a the abbreviation of the week. Eg:tue
%A the full name of the week. Eg:tuesday
The abbreviation for the%b month name.
The full name of the%B month name.
%c Local End Date time is a better representation string.
%d numbers indicate the day of the month (range 00 to 31). Date
%H uses a 24-hour system number to indicate the number of hours (range 00 to 23).
%I A 12-hour number is used to indicate the number of hours (ranging from 01 to 12).
%j the number of days of the year (ranging from 001 to 366).
Number of%m months (ranging from 1 to 12).
%m minutes.
%p indicates the local end time with ' AM ' or ' PM '.
%s Number of seconds.
The%u number is expressed as the week ordinal of the year, and the first one week begins in Sunday.
The%w number is expressed as the week ordinal of the year, and the first one week begins in Monday.
%w the number of days of the week (0 for Sunday).
%x does not contain a date representation of time.
%x does not contain a time representation of dates. Eg:15:26:30
%y two digits indicates the year (range from 00 to 99).
%Y full year digits, that is, four digits. eg:2008
%Z (%Z) time zone or name abbreviation. EG: China Standard Time
%%% character.

Scheme Two advantages: can be accurate to the millisecond; disadvantage: Use the win API
#include <windows.h>
#include <stdio.h>
int main (void)
{
SYSTEMTIME SYS;
Getlocaltime (&sys);
printf ("%4d/%02d/%02d%02d:%02d:%02d.%0 3d Week%1d\n ", Sys.wyear,sys.wmonth,sys.wday,sys.whour,sys.wminute, Sys.wsecond,sys.wmilliseconds,sys.wdayofweek);
return 0;
}
Scheme III, advantages: the use of system functions, but also to modify the system time
This file must be a C + + file
#include <stdlib.h>
#include <iostream>
using namespace Std;
void Main ()
{
System ("Time");
}
Scenario four, the current time is converted to a second level, and then the corresponding time conversion can be
This file must be a C + + file
#include <iostream>
#include <ctime>
Using> cout<<now_time;
return 0;
}


(2): The program acquires system privileges and occupies a single thread:


(3): C + + direct use interruption:



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.