Windows Driver: Get the current system time and generate a format string

Source: Internet
Author: User

Follow these steps:

1. Use kequerysystemtime () to obtain the current GMT system time. This is a count from 1601-01-01 (unit: 100ns ).

2. Call exsystemtimetolocaltime () to convert the GMT system time value to the local system time in the current time zone.

3. Use rtltimetotimefields () to convert the system time value to the format of Year: Month: Day: hour: minute: Second, Which is saved in a time_fields structure.

Typedef struct time_fields
{
Cshort year;
Cshort month;
Cshort Day;
Cshort hour;
Cshort minute;
Cshort second;
Cshort milliseconds;
Cshort weekday;
} Time_fields;


Sample Code to obtain the time string function:

(This function will later use: Windows Driver: to output debugging information to the file like dbuplintf)

(PS: is there a better format for source code)

//----------------------------------------------------------------------
//
// Getcurrenttimestring
//
// Get current time string. (Format: % d-% 02d-% 02d % 02d: % 02d: % 02d)
//
//----------------------------------------------------------------------
Pchar
Getcurrenttimestring ()
{
Static char sztime [128];
Large_integer systemtime;
Large_integer localtime;
Time_fields timefiled;

Kequerysystemtime (& systemtime );
Exsystemtimetolocaltime (& systemtime, & localtime );
Rtltimetotimefields (& localtime, & timefiled );
Sprintf (sztime, "% d-% 02d-% 02d % 02d: % 02d: % 02d"
, Timefiled. Year
, Timefiled. Month
, Timefiled. Day
, Timefiled. Hour
, Timefiled. Minute
, Timefiled. Second
);

Return sztime;
}

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.