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

📄 jntime.cpp

📁 此次上传的使linux下的文件传输协议
💻 CPP
字号:
#include "stdafx.h"
#include "Prog.h"
#include "JnTime.h"

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

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

JnTime::JnTime()
{

}

JnTime::~JnTime()
{

}

/***************************************************************************
函数名称:VsSecondShort
函数功能:比较两个时间的大小
函数原理:返回两个时间之间的差值
****************************************************************************/
int JnTime::VsSecondShort(CString sTime1, CString sTime2)
{
	COleDateTime var=COleVariant(sTime1);
	COleDateTime var1=COleVariant(sTime2);
	CTime t1(2000,01,01,var.GetHour(),var.GetMinute(),var.GetSecond()); 
	CTime t2(2000,01,01,var1.GetHour(),var1.GetMinute(),var1.GetSecond()); 
	CTimeSpan ts=t2-t1;
	return (int)ts.GetTotalSeconds();
}

/***************************************************************************
函数名称:VsSecondLong
函数功能:比较带日期的两个时间的大小
函数原理:返回两个时间之间的差值
****************************************************************************/
int JnTime::VsSecondLong(CString sTime1, CString sTime2)
{
	COleDateTime var=COleVariant(sTime1);
	COleDateTime var1=COleVariant(sTime2);
	CTime t1(var.GetYear(),var.GetMonth(),var.GetDay(),var.GetHour(),var.GetMinute(),var.GetSecond()); 
	CTime t2(var1.GetYear(),var1.GetMonth(),var1.GetDay(),var1.GetHour(),var1.GetMinute(),var1.GetSecond()); 
	CTimeSpan ts=t2-t1;
	return (int)ts.GetTotalSeconds();
}

/***************************************************************************
函数名称:SetPickerTime
函数功能:设置ActiveX控件CDTPicker的显示时间(HH:MM:SS)值
函数原理:通过OleVariant将字符串的时间设置到控件上面去
****************************************************************************/
void JnTime::SetPickerTime(CDTPicker &pDate, CString sTime)
{
	pDate.SetValue(COleVariant(sTime));
}

/***************************************************************************
函数名称:TransDate
函数功能:返回不同格式的时间字符串值
函数原理:
****************************************************************************/
CString JnTime::TransDate(CString sDate, int nType)
{
	COleVariant var(sDate);
	CString str=_T("");
	switch(nType)
	{
	case 0:  // YYYY/MM/DD
		str=COleDateTime(var).Format(_T("%Y/%m/%d"));
		break;
	case 1:  // #YYYY/MM/DD#
		str=COleDateTime(var).Format(_T("#%Y/%m/%d#"));
		break;
	case 2:  // YYYY年MM月DD日
		str=COleDateTime(var).Format(_T("%Y年%m月%d日"));
		break;
	case 3:  // #MM/DD/YYYY HH:MM:SS#
		str=COleDateTime(var).Format(_T("#%m/%d/%Y %H:%M:%S#"));
		break;
	case 4:  // YYYY年MM月DD日 HH时MM分SS秒
		str=COleDateTime(var).Format(_T("%Y年%m月%d日 %H时%M分%S秒"));
		break;
	case 5:  // #MM/DD/YYYY#
		str=COleDateTime(var).Format(_T("#%m/%m/%Y#"));
		break;
	case 6:  // HH:MM:SS
		str=COleDateTime(var).Format(_T("%H:%M:%S"));
		break;
	case 7:  // YYYYMMDD
		str=COleDateTime(var).Format(_T("%Y%m%d"));
		break;
	case 8:  // YYYY-MM-DD
		str=COleDateTime(var).Format(_T("%Y-%m-%d"));
		break;
	case 9:  // 'YYYY-MM-DD HH:MM:SS'
		str=COleDateTime(var).Format(_T("'%Y-%m-%d %H:%M:%S'"));
		break;
	case 10: // yyMMDD
		str=COleDateTime(var).Format(_T("%y%m%d"));
		break;
	case 11:  // YYYY-MM-DD HH:MM:SS
		str=COleDateTime(var).Format(_T("%Y-%m-%d %H:%M:%S"));
		break;
	case 12:  // YY-MM-DD
		str=COleDateTime(var).Format(_T("%y-%m-%d"));
		break;
	case 13: //YY年
		str=COleDateTime(var).Format(_T("%Y年%m月"));
		break;
	case 14:  // 'YYYY/MM/DD'
		str=COleDateTime(var).Format(_T("'%Y/%m/%d'"));
		break;
	case 15:  // 'YYYY/MM/DD HH:MM:SS'
		str=COleDateTime(var).Format(_T("'%Y/%m/%d %H:%M:%S'"));
		break;
	case 16:  //MM
		str=COleDateTime(var).Format(_T("%m"));
		break;
	case 17:  // YYYY/MM/DD HH:MM:SS
		str=COleDateTime(var).Format(_T("%Y/%m/%d %H:%M:%S"));
		break;
	case 18:  // mm月DD日HH:MM
		str=COleDateTime(var).Format(_T("%m月%d日%H:%M"));
		break;
	case 19:  // YYYY
		str=COleDateTime(var).Format(_T("%Y"));
		break;
	case 20:  //yymmddHHMMSS
		str=COleDateTime(var).Format(_T("%y%m%d%H%M%S"));
		break;
	case 21:  //mm月dd日
		str=COleDateTime(var).Format(_T("%m月%d日"));
		break;
	}
	if(str==_T("无效的日期时间。"))
	{
		str=_T("");
	}
	return str;
}

/***************************************************************************
函数名称:GetNewDate
函数功能:获得按照nDay偏移的时间数值
函数原理:
****************************************************************************/
CString JnTime::GetNewDate(CString sDate, int nDay)
{
	COleDateTimeSpan sp(0,nDay,0,0);
	COleDateTime date=COleVariant(sDate);
	date+=sp;
	return date.Format(_T("%Y年%m月%d日 %H时%M分%S秒"));
}

/***************************************************************************
函数名称:GetPickerTime
函数功能:获得CDTPicker当前显示的时间值
函数原理:
****************************************************************************/
CString JnTime::GetPickerTime(CDTPicker &pDate)
{
	return COleDateTime(pDate.GetValue()).Format(_T("%H:%M:%S"));
}

/***************************************************************************
函数名称:GetCurSysTime
函数功能:根据给定的参数nType返回不同格式化的当前时间
函数原理:
****************************************************************************/
CString JnTime::GetCurSysTime(int nType)
{
	CTime ptime=CTime::GetCurrentTime();
	return TransDate(ptime.Format(_T("%Y年%m月%d日 %H:%M:%S")),nType);
}

/***************************************************************************
函数名称:GetPickerDate
函数功能:获得CDTPicker当前显示的日期时间值
函数原理:
****************************************************************************/
CString JnTime::GetPickerDate(CDTPicker &pDate)
{
	return COleDateTime(pDate.GetValue()).Format(_T("%Y年%m月%d日 %H:%M:%S"));
}

/***************************************************************************
函数名称:VsHour
函数功能:比较两个时间数值小时的大小
函数原理:
****************************************************************************/
BOOL JnTime::VsHour(CString sTime1, CString sTime2)
{
	COleDateTime var=COleVariant(sTime1);
	COleDateTime var1=COleVariant(sTime2);
	CTime t1(2000,01,01,var.GetHour(),0,0); 
	CTime t2(2000,01,01,var1.GetHour(),0,0); 
	CTimeSpan ts=t2-t1;
	if(ts.GetTotalSeconds()>=0)
		return TRUE;
	else 
		return FALSE;
}

/***************************************************************************
函数名称:VsWeek
函数功能:比较两个时间数值星期上的大小
函数原理:
****************************************************************************/
BOOL JnTime::VsWeek(CString sWeek1, CString sWeek2)
{
	int n1,n2,n3;
	sWeek1.Replace("星期","");
	sWeek2.Replace("星期","");
	n1=theApp.jns.StrToInt1(sWeek1);
	if(n1==0 || n1==8)
		n1=1;
	else
		n1++;
	n2=theApp.jns.StrToInt1(sWeek2);
	if(n2==0 || n2==8)
		n2=1;
	else
		n2++;
	CTime ptime=CTime::GetCurrentTime();
	n3=ptime.GetDayOfWeek();
	if(n3>=n1 || n3<=n2)
		return TRUE;
	else
		return FALSE;
}

/***************************************************************************
函数名称:VsWeek
函数功能:比较两个时间数值日期上的大小
函数原理:
****************************************************************************/
int JnTime::VsDate(CString sDate1, CString sDate2)
{
	COleDateTime var=COleVariant(sDate1);
	COleDateTime var1=COleVariant(sDate2);
	CTime t1(var.GetYear(),var.GetMonth(),var.GetDay(),0,0,0); 
	CTime t2(var1.GetYear(),var1.GetMonth(),var1.GetDay(),0,0,0); 
	CTimeSpan ts=t2-t1;
	long l=(long)ts.GetTotalSeconds();
	if(l>0)       //sDate2>sDate1
		return 1;
	if(l==0)      //sDate2==sDate1
		return 2;
	if(l<0)       //sDate2<sDate1
		return 3;
	return -1;
}

CString JnTime::GetWeek(CString sDate)
{
	COleDateTime var=COleVariant(sDate);
	CTime t1(var.GetYear(),var.GetMonth(),var.GetDay(),0,0,0);
	int nWeek=t1.GetDayOfWeek();
	CString str=_T("星期");
	switch(nWeek)
	{
	case 1:
		str+=_T("日");
		break;
	case 2:
		str+=_T("一");
		break;
	case 3:
		str+=_T("二");
		break;
	case 4:
		str+=_T("三");
		break;
	case 5:
		str+=_T("四");
		break;
	case 6:
		str+=_T("五");
		break;
	case 7:
		str+=_T("六");
		break;
	default:
		break;
	}
	return str;
}	

int JnTime::GetDataVs(CString sDate1,CString sDate2)
{
	COleDateTime var=COleVariant(sDate1);
	COleDateTime var1=COleVariant(sDate2);
	CTime t1(var.GetYear(),var.GetMonth(),var.GetDay(),0,0,0); 
	CTime t2(var1.GetYear(),var1.GetMonth(),var1.GetDay(),0,0,0); 
	CTimeSpan ts=t2-t1;
	return (int)ts.GetDays();
}

CString JnTime::GetNewMin(CString sDate, int nMin)
{
	COleDateTimeSpan sp(0,0,nMin,0);
	COleDateTime date=COleVariant(sDate);
	date+=sp;
	return date.Format(_T("%Y年%m月%d日 %H时%M分%S秒"));
}

BOOL JnTime::VsMin(CString sTime1, CString sTime2)
{
	COleDateTime var=COleVariant(sTime1);
	COleDateTime var1=COleVariant(sTime2);
	CTime t1(2000,01,01,var.GetHour(),var.GetMinute(),var.GetSecond()); 
	CTime t2(2000,01,01,var1.GetHour(),var1.GetMinute(),var1.GetSecond()); 
	CTimeSpan ts=t2-t1;
	if(ts.GetTotalSeconds()>=0)
		return TRUE;
	else 
		return FALSE;
}

void JnTime::SetPickerTime(CDTPicker &pDate)
{
	pDate.SetValue(COleVariant(GetCurSysTime(0)));
}

long JnTime::GetDateLong(CString sDate)
{
	COleDateTime var=COleVariant(sDate);
	CTime t1(var.GetYear(),var.GetMonth(),var.GetDay(),var.GetHour(),var.GetMinute(),var.GetSecond());
	CTime t2(2000,01,01,0,0,0); 
	CTimeSpan ts=t1-t2;
	return (long)ts.GetTotalSeconds();
}

int JnTime::GetSjc(CString sSj1, CString sSj2, int nType)
{
	COleDateTime var=COleVariant(sSj1);
	COleDateTime var1=COleVariant(sSj2);
	CTime t1(var.GetYear(),var.GetMonth(),var.GetDay(),var.GetHour(),var.GetMinute(),var.GetSecond()); 
	CTime t2(var1.GetYear(),var1.GetMonth(),var1.GetDay(),var1.GetHour(),var1.GetMinute(),var1.GetSecond()); 
	CTimeSpan ts=t2-t1;
	int nRet=0;
	switch(nType)
	{
	case 0:  //返回秒
		nRet=ts.GetSeconds(); 
		break;
	case 1:
		nRet=ts.GetMinutes();
		break;
	case 2:
		nRet=ts.GetHours();
		break;
	case 3:
		nRet=ts.GetDays();
		break;
	default:
		break;
	}
	return nRet;
}

int JnTime::VsMin1(CString sTime1, CString sTime2)
{
	COleDateTime var=COleVariant(sTime1);
	COleDateTime var1=COleVariant(sTime2);
	CTime t1(2000,01,01,var.GetHour(),var.GetMinute(),var.GetSecond()); 
	CTime t2(2000,01,01,var1.GetHour(),var1.GetMinute(),var1.GetSecond()); 
	CTimeSpan ts=t2-t1;
	if(ts.GetTotalSeconds()<0)
	{
		return -1;
	}
	else if(ts.GetTotalSeconds()==0)
	{
		return 0;
	}
	else 
	{
		return 1;
	}
}

CString JnTime::ToAdd(CString sDate)
{
	return TransDate(sDate,11);
}

CString JnTime::ToSqlWhere(CString sDate)
{
	return TransDate(sDate,9);
}

CString JnTime::ToMdbWhere(CString sDate)
{
	return TransDate(sDate,3);
}

int JnTime::VsDate1(CString sDate1, CString sDate2)
{
	COleDateTime var=COleVariant(sDate1);
	COleDateTime var1=COleVariant(sDate2);
	CTime t1(var.GetYear(),var.GetMonth(),var.GetDay(),0,0,0); 
	CTime t2(var1.GetYear(),var1.GetMonth(),var1.GetDay(),0,0,0); 
	CTimeSpan ts=t2-t1;
	long l=(long)ts.GetTotalSeconds();
	return l;
}

CString JnTime::GetNewYearDate(CString sDate, int nYear)
{
	COleDateTime date=COleVariant(sDate);
	date.SetDate(date.GetYear()+nYear,date.GetMonth(),date.GetDay());
	return date.Format(_T("%Y年%m月%d日 %H时%M分%S秒"));
}

⌨️ 快捷键说明

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