代码改变世界

windows api 每日一练(4)时间操作

2009-11-17 14:06  Clingingboy  阅读(1576)  评论(0编辑  收藏  举报

 


1.获取和设置系统时间

void WINAPI GetSystemTime(
  __out  LPSYSTEMTIME lpSystemTime
);
BOOL WINAPI SetSystemTime(
  __in  const SYSTEMTIME* lpSystemTime
);


 

2.获取和设置本地时间

void WINAPI GetLocalTime(
  __out  LPSYSTEMTIME lpSystemTime
);
BOOL WINAPI SetLocalTime(
  __in  const SYSTEMTIME* lpSystemTime
);

 

3.获取和设置文件时间

BOOL WINAPI GetFileTime(
  __in       HANDLE hFile,
  __out_opt  LPFILETIME lpCreationTime,
  __out_opt  LPFILETIME lpLastAccessTime,
  __out_opt  LPFILETIME lpLastWriteTime
);
BOOL WINAPI SetFileTime(
  __in      HANDLE hFile,
  __in_opt  const FILETIME* lpCreationTime,
  __in_opt  const FILETIME* lpLastAccessTime,
  __in_opt  const FILETIME* lpLastWriteTime
);

 
4.时间转换

(1)系统时间,本地时间,文件时间互换

void WINAPI GetSystemTimeAsFileTime(
  __out  LPFILETIME lpSystemTimeAsFileTime
);
BOOL WINAPI SystemTimeToFileTime(
  __in   const SYSTEMTIME* lpSystemTime,
  __out  LPFILETIME lpFileTime
);

 

BOOL WINAPI FileTimeToSystemTime(
  __in   const FILETIME* lpFileTime,
  __out  LPSYSTEMTIME lpSystemTime
);
BOOL WINAPI LocalFileTimeToFileTime(
  __in   const FILETIME* lpLocalFileTime,
  __out  LPFILETIME lpFileTime
);


Test

#include <windows.h>
#include <stdio.h>
#include <iostream>
int main()
{
SYSTEMTIME  sysTime;
::GetSystemTime(&sysTime);
::GetLocalTime(&sysTime);
sysTime.wYear=2010;
::SetLocalTime(&sysTime);
::GetSystemTime(&sysTime);
}