BOOL SystemTimeToFileTime(const SYSTEMTIME* lpSystemTime,LPFILETIME lpFileTime);The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
VariantTimeToSystemTime Converts the variant representation of time to system time values.INT VariantTimeToSystemTime( double vtime, LPSYSTEMTIME lpSystemTime ); Parameters vtime The variant time that will be converted. lpSystemTime Pointer to the location where the converted time will be stored. Return Value The return value obtained from the returned INT is one of the following.Value Meaning TRUE Success. FALSE Failure. Comments A variant time is stored as an 8-byte real value (double), representing a date between January 1, 100 and December 31, 9999, inclusive. The value 2.0 represents January 1, 1900; 3.0 represents January 2, 1900, and so on. Adding 1 to the value increments the date by a day. The fractional part of the value represents the time of day. Therefore, 2.5 represents noon on January 1, 1900; 3.25 represents 6:00 A.M. on January 2, 1900, and so on. Negative numbers represent the dates prior to December 30, 1899.Using the SYSTEMTIME structure is useful because: It spans all time/date periods. MS-DOS date/time is limited to representing only those dates between 1/1/1980 and 12/31/2107. The date/time elements are all easily accessible without needing to do any bit decoding. The National Language Support data and time formatting functions GetDateFormat and GetTimeFormat take a SYSTEMTIME value as input. It is the default Win32 time and date data format supported by Windows NT and Windows 95. The VariantTimeToSystemTime function will accept invalid dates and try to fix them when resolving to a VARIANT time. For example, an invalid date such as 2/29/2001 will resolve to 3/1/2001. Only days are fixed, so invalid month values result in an error being returned. Days are checked to be between 1 and 31. Negative days and days greater than 31 results in an error. A day less than 31 but greater than the maximum day in that month has the day promoted to the appropriate day of the next month. A day equal to zero resolves as the last day of the previous month. For example, an invalid dates such as 2/0/2001 will resolve to 1/31/2001.Requirements Windows NT/2000: Requires Windows NT 3.1 or later. Windows 95/98: Requires Windows 95 OSR2 or later. Header: Declared in oleauto.h. Library: Use oleaut32.lib.
LPSYSTEMTIME lpSystemTime // system time
);
我是想转换成systemtime的格式啊!我的任务就是转换,可是,大家也知道,每个月的天数都不同,我怎么算呢!
我找遍了,都没有找到直接转换的函数。
{
WORD wYear; //当前年份,大于1601年
WORD wMonth; //1 = 1月,2 = 2月,以此类推
WORD wDayOfWeek; // 0 = 周日,1 = 周一,2 = 周二,以此类推
WORD wDay; // 当前几号
WORD wHour; //当前钟点
WORD wMinute; // 当前分钟
WORD wSecond; //当前秒钟
WORD wMilliseconds; //当前毫秒
} SYSTEMTIME, *PSYSTEMTIME;
时间间隔为0.1毫秒天那,你叫我怎么转换成SYSTEMTIME类型啊!!!!
Converts the variant representation of time to system time values.INT VariantTimeToSystemTime(
double vtime,
LPSYSTEMTIME lpSystemTime
);
Parameters
vtime
The variant time that will be converted.
lpSystemTime
Pointer to the location where the converted time will be stored.
Return Value
The return value obtained from the returned INT is one of the following.Value Meaning
TRUE Success.
FALSE Failure. Comments
A variant time is stored as an 8-byte real value (double), representing a date between January 1, 100 and December 31, 9999, inclusive. The value 2.0 represents January 1, 1900; 3.0 represents January 2, 1900, and so on. Adding 1 to the value increments the date by a day. The fractional part of the value represents the time of day. Therefore, 2.5 represents noon on January 1, 1900; 3.25 represents 6:00 A.M. on January 2, 1900, and so on. Negative numbers represent the dates prior to December 30, 1899.Using the SYSTEMTIME structure is useful because: It spans all time/date periods. MS-DOS date/time is limited to representing only those dates between 1/1/1980 and 12/31/2107.
The date/time elements are all easily accessible without needing to do any bit decoding.
The National Language Support data and time formatting functions GetDateFormat and GetTimeFormat take a SYSTEMTIME value as input.
It is the default Win32 time and date data format supported by Windows NT and Windows 95.
The VariantTimeToSystemTime function will accept invalid dates and try to fix them when resolving to a VARIANT time. For example, an invalid date such as 2/29/2001 will resolve to 3/1/2001. Only days are fixed, so invalid month values result in an error being returned. Days are checked to be between 1 and 31. Negative days and days greater than 31 results in an error. A day less than 31 but greater than the maximum day in that month has the day promoted to the appropriate day of the next month. A day equal to zero resolves as the last day of the previous month. For example, an invalid dates such as 2/0/2001 will resolve to 1/31/2001.Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 OSR2 or later.
Header: Declared in oleauto.h.
Library: Use oleaut32.lib.
时间间隔为0.1毫秒。可以这样,可以计算出其1天有多少个0.1毫秒吧,也就是864000000个0.1毫秒,
非润年是365天也就是315360000000个0.1膏秒,润年是366天是316224000000个0.1毫秒,一个润和非润的周期就是3 * 315360000000 + 316224000000 = 1262304000000,用当前值除以1262304000000再取顶(2.0 = 2, 2.1 = 3),可以得到当前是第几个周期,除运算的余数保留为m。
用m除以315360000000再取顶,可以得到在当前周期中是第几年,余数保留为p。
如果是第1 - 3年,那么则是非润年,用先将p整除到天单元的,建一个每月天数表,可以计算出p属于哪一月,再减去前面月份的总天数就可以计算出p是哪一天,以此类推,时、分、秒、毫秒就都计算出来了。
年份就等于1600 + 4 * ( 周期数 - 1 ) + m。_SYSTEMTIME中还有一个星期几的值,当你得到年月日以后,可以通过一些公式计算出来,这些公式网上到处都是,我就不多说了。
void TimeToSystemTime(LARGE_INTEGER tTime, PSYSTEMTIME pSysTime)
{
int MonthDay = 0;
pSysTime->wYear = 1601 + tTime.QuadPart / 315360000000L;
tTime.QuadPart = tTime.QuadPart % 315360000000L;//È¡µÃÓàϵÄÔ·Ý
pSysTime->wMonth = 1 + tTime.QuadPart / 25920000000L;
tTime.QuadPart = tTime.QuadPart % 25920000000L;
switch(pSysTime->wMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
MonthDay = 31;
break;
case 2:
{
if((pSysTime->wYear % 4 == 0) ||
((pSysTime->wYear % 100 == 0)&&(pSysTime->wYear % 400 == 0)))//ÈòÔÂ
MonthDay = 28;
else//·ÇÈòÔÂ
MonthDay = 29;
}
break;
case 4:
case 6:
case 9:
case 11:
MonthDay = 31;
break;
default:
//·¢Éú´íÎó
MonthDay = 0;
}
if(tTime.QuadPart / 864000000L >= MonthDay)//˵Ã÷³¬³öÁË
{
pSysTime->wMonth += 1;
tTime.QuadPart = tTime.QuadPart - MonthDay * 864000000L;
}
pSysTime->wDay = 1 + tTime.QuadPart / 864000000L;
tTime.QuadPart = tTime.QuadPart % 864000000;
pSysTime->wHour = 0 + tTime.QuadPart / 36000000L;
tTime.QuadPart = tTime.QuadPart % 36000000L;
pSysTime->wMinute = 0 + tTime.QuadPart / 600000L;
tTime.QuadPart = tTime.QuadPart % 600000L;
pSysTime->wSecond = tTime.QuadPart / 10000L;
tTime.QuadPart = tTime.QuadPart % 10000L;
pSysTime->wMilliseconds = tTime.QuadPart / 10L;
////////////////////////////////////////////////////////
//ÏÂÃ濪ʼ¼ÆËãÕâÌìÊÇÐÇÆÚ¼¸
int Ydiff,Ddiff,Mdiff;
int DAY[7]={0, 1, 2, 3, 4, 5, 6};
//"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
int cd,cm,cy,cs,rd,rm,ry,rs,i;
cd=19;cm=2;cy=2001;cs=2; // setting 19 feb 2001 , Monday
ry = pSysTime->wYear;
rm = pSysTime->wMonth;
rd = pSysTime->wDay;
// difference in years
Ydiff=cy-ry;
// find no of leap years
if(cy>=ry)
{
for(i=cy;i>=ry;i--)
{
if((i%100)==0) // for a century
{
if((i%400)==0) {Ydiff++;}
}
else
{
if((i%4)==0) {Ydiff++;}
}
}
}
else
{
for(i=cy;i<ry;i++)
{
if((i%100)==0) // for a century
{
if((i%400)==0) {Ydiff--;}
}
else
{
if((i%4)==0) {Ydiff--;}
}
}
}
Ydiff=Ydiff%7;
Ddiff=(cd-rd)%7;
rs=cs-(Ydiff+Ddiff)%7;
rs=rs%7;
//difference in months
Mdiff=cm-rm;
if(Mdiff<0)
{
for(i=cm;i<rm;i++)
{
switch(i)
{
case 1:rs+=3;break;
case 2:if((ry%4)==0) {rs++;}
break;
case 3:rs+=3;break;
case 4:rs+=2;break;
case 5:rs+=3;break;
case 6:rs+=2;break;
case 7:rs+=3;break;
case 8:rs+=3;break;
case 9:rs+=2;break;
case 10:rs+=3;break;
case 11:rs+=2;break;
default:
break;
}
}
rs=rs%7;
}
if(Mdiff>0)
{
for(i=cm;i>rm;i--)
{
switch(i)
{
case 2:rs-=3;break;
case 3:if(((ry-1)%4)==0) {rs--;}
break;
case 4:rs-=3;break;
case 5:rs-=2;break;
case 6:rs-=3;break;
case 7:rs-=2;break;
case 8:rs-=3;break;
case 9:rs-=3;break;
case 10:rs-=2;break;
case 11:rs-=3;break;
case 12:rs-=2;break;
default:
break;
}
}
rs=rs%7;
}
if(rs<=0) {rs=7+rs;}
pSysTime->wDayOfWeek = DAY[rs-1]; return;
}好像不行啊
直接转换就成了。给分大家再次谢谢各位!!!!结果如下:
void ConvertToSystemTime(LARGE_INTEGER tTime, PSYSTEMTIME pSysTime)
{
FILETIME ft;
ft = *(FILETIME*)&tTime;
FileTimeToSystemTime(&ft, pSysTime);
}