⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timehelper.h

📁 270的linux说明
💻 H
字号:
/*

Copyright (c) 2008, Intel Corporation. 

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:


    * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution.

    * Neither the name of Intel Corporation nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.

*///==============================================================================// collection.h : Declaration of template Collection//==============================================================================#if !defined(AFX_TIMEHELPER_H__0C954835_3E21_4097_8748_22EBE8591D3E__INCLUDED_)#define AFX_TIMEHELPER_H__0C954835_3E21_4097_8748_22EBE8591D3E__INCLUDED_#include "inc/framework/win2linux.h"#include <time.h>class CTimeHelper  {public:	//UNIXTIME => FILETIME	/*	static void UnixTime2FileTime(time_t t, LPFILETIME pft)	{	 // Note that LONGLONG is a 64-bit value		 LONGLONG ll;		 ll = Int32x32To64(t, 10000000) + 116444736000000000;		 pft->dwLowDateTime = (DWORD)ll;		 pft->dwHighDateTime = (ULONG)(ll >> 32);	}	*/	//UNIXTIME => SYSTEMTIME	/*	static void UnixTime2SystemTime(time_t t, LPSYSTEMTIME pst)	{		 FILETIME ft;		 UnixTime2FileTime(t, &ft);		 FileTimeToSystemTime(&ft, pst);	}	*/	static void UnixTime2SystemTime(time_t t, struct tm *pst)	{		pst = gmtime(&t);	}/*fix SCR #314 SYSTEMTIME range: from year 1601 to year 30827 (on Windows Server 2003, Windows XP)time_t range: from midnight, January 1, 1970 to Tue Jan 19 03:14:07 2038, sub-set of SYSTEMTIME rangeif the input SYSTEMTIME or FILETIME is out of the range of time_t, FileTime2UnixTime and SystemTime2UnixTime return FALSE*/	//FILETIME => UNIXTIME	/*	static BOOL FileTime2UnixTime(FILETIME *pFt, time_t *pt)	{		//January 1, 1970 		static SYSTEMTIME stLowerLimit = {1970, 1, 0, 1, 0, 0, 0, 0};		//January 19, 2038		static SYSTEMTIME stUpperLimit = {2038, 1, 2, 19, 03, 14, 07, 0};		static FILETIME ftLowerLimit;		static FILETIME ftUpperLimit;		static BOOL bFirst = TRUE;		if(bFirst)		{			SystemTimeToFileTime(&stLowerLimit, &ftLowerLimit);			SystemTimeToFileTime(&stUpperLimit, &ftUpperLimit);			bFirst = FALSE;		}		if(CompareFileTime(pFt, &ftLowerLimit) < 0 			|| CompareFileTime(pFt, &ftUpperLimit) > 0)			return FALSE;		__int64 IntelUnixTime;		IntelUnixTime = ((__int64)pFt->dwHighDateTime << 32) + 			pFt->dwLowDateTime;		IntelUnixTime -= 116444736000000000;		IntelUnixTime /= 10000000; 		*pt = (time_t)IntelUnixTime;		return TRUE;	}	*/	//SYSTEMTIME => UNIXTIME	/*	static BOOL SystemTime2UnixTime(SYSTEMTIME *pSt, time_t *pt)	{		FILETIME ft;		SystemTimeToFileTime(pSt, &ft);		return FileTime2UnixTime(&ft, pt);	}	*/	static BOOL SystemTime2UnixTime(struct tm *pSt, time_t *pt)	{		*pt = mktime(pSt);	}	#define MAX_TIMET 0x7FFFFFFF	static DATE timet2date(time_t time)	{		if ( time < 0 )			return 0;		if ( time > MAX_TIMET )			return 0;		long double temp = 25569+1.0/3+time*1.0/(24*3600);		return DATE(temp);	}	static time_t date2timet(DATE date)	{		long double temp = timet2date(0);		if ( date < temp )			return -1;		if ( date > timet2date(MAX_TIMET) )			return -1;		temp = (date - temp)*24*3600;		return time_t(temp + 0.5);	}};#endif // !defined(AFX_TIMEHELPER_H__0C954835_3E21_4097_8748_22EBE8591D3E__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -