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

📄 stddate.cpp

📁 beereader source code
💻 CPP
字号:
// StdDate.cpp: implementation of the CStdDate class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "StdDate.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CStdDate::CStdDate()
{
	m_Time = CTime::GetCurrentTime(); 
}
	
CStdDate::~CStdDate()
{

}

void CStdDate::SetDateTime(CString date)
{
	//从RFC822日期格式转换成标准日期格式。
	if( !date.IsEmpty() )
	   m_Time = TranDateString( date );
}

void  CStdDate::SetDateTime( CTime date )
{
	m_Time = date;
}

CString CStdDate::GetTimeString()
{
	CString szReturn;
	szReturn = m_Time.Format( _T("%Y/%m/%d %H:%M:%S") );
	return szReturn;
}

CTime CStdDate::GetDateTime()
{
	return m_Time;
}

CTime CStdDate::TranDateString(CString szDate)
{
	CString strValue = szDate;

	if( strValue.Find(_T(",") ) < 0 ) return CTime::GetCurrentTime();
	
	int		nPos;
	int		nZone = -1;
	strValue.MakeUpper();
	CString szMonth[12] = { _T("JAN"), _T("FEB"), _T("MAR"), _T("APR"),
                    _T("MAY"), _T("JUN"), _T("JUL"), _T("AUG"),
					_T("SEP"), _T("OCT"), _T("NOV"), _T("DEC") };

	if(	strValue.Replace( _T("GMT"),  _T("") ) != 0 || 
		strValue.Replace( _T("UT"), _T("") )!= 0 )
		nZone = ZONE_GMT;
	if( strValue.Replace( _T("PST"),  _T("") ) !=0 ||
		strValue.Replace( _T("PDT"), _T("") ) != 0 )
		nZone = ZONE_PST;
	if( strValue.Replace( _T("EST"),  _T("") ) !=0 ||
		strValue.Replace( _T("EDT"), _T("") ) != 0 )
		nZone = ZONE_EST;
	if( strValue.Replace( _T("MST"),  _T("") ) !=0 ||
		strValue.Replace( _T("MDT"), _T("") ) != 0 )
		nZone = ZONE_MST;	
    
	if( nZone < 0 ) nZone = ZONE_GMT;

    int iMonth = -1;
	
	for( int i = 0; i < 12 ; i++ )
	 {
		if( strValue.Replace(  szMonth[i],_T("") ) != 0 )
		{
			iMonth = i + 1;
			break;
		}
	 }

	if( iMonth < 0 )
		iMonth = CTime::GetCurrentTime().GetMonth();

	strValue = strValue.Right(strValue.GetLength()-4);
	/*
	strValue.Replace( _T("MON,"), _T("") );
	strValue.Replace( _T("TUE,"), _T("") );
	strValue.Replace( _T("WED,"), _T("") );
	strValue.Replace( _T("THU,"), _T("") );
	strValue.Replace( _T("FRI,"), _T("") );
	strValue.Replace( _T("SAT,"), _T("") );
	strValue.Replace( _T("SUN,"), _T("") );	
  */
	strValue.TrimLeft();
	strValue.TrimRight();
	nPos = strValue.ReverseFind( '-' );
	if ( strValue.GetLength() - nPos == 5 )
	{
		strValue = strValue.Left( nPos-1 );
		strValue.TrimRight();
	}

	int iYear=2004,iDay=1,iHour=0,iMin=0,iSec=0;

	nPos = strValue.Find( _T(" ") );
	int iFlag = 0;
	CString szTemp;
	while( nPos > 0 )
	{
		szTemp = strValue.Left(nPos+1);
		strValue = strValue.Right( strValue.GetLength()-nPos-1 );
		szTemp.TrimLeft();
		szTemp.TrimRight();
		strValue.TrimLeft();
		strValue.TrimRight();
		
		int iValue = atoi( (LPTSTR)(LPCTSTR)szTemp);
		if( iFlag == 1 )
		{
			if( iValue < 100 ) 
				iYear = 2000 + iValue;
			 else
				iYear = iValue;
		}
		else if( iFlag == 0 )
			iDay = iValue;
        else if( iFlag == 2 )
			iHour = iValue;
		else if( iFlag == 3 )
		{
			iMin = iValue;
		    iSec = atoi( (LPTSTR)(LPCTSTR)strValue);
			break;
		}
		iFlag++;

		if( iFlag <= 1 )
           nPos = strValue.Find( _T(" ") );
		else
		   nPos = strValue.Find(_T(":") );
	}

	return CTime(iYear,iMonth,iDay,iHour,iMin,iSec);
}

CString CStdDate::GetDateString(CTime time)
{
	CString szReturn;
	szReturn = time.Format( _T("%a, %d %b %Y %H:%M:%S GMT") );

	return szReturn;
}

⌨️ 快捷键说明

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