CTime类使用小结
来源:互联网 发布:ue软件算法 编辑:程序博客网 时间:2024/05/22 06:16
1.初始化
m_begintime=CTime(2004,1,1,0,0,0,-1);//参数依次为year,month,day,hour,minite,second
m_endtime =CTime::GetCurrentTime();//当前时间
2.日期比较
CTimeSpan span;
span=time1-time2;
得到两时间的间隔.
可以取得span.GetHours().等
3.access数据库查询
使用DateDiff()函数,具体参照access帮助
CString timesql;
timesql.Format(" Where DateDiff('d',%s,'%s')<=0","日期",m_begintime.Format("%Y-%m-%d"));
4读取日期字段(odbc)
CDBVariant var;
recset.GetFieldValue(i,var);
s.Format("%d-%d-%d",(var.m_pdate)->year,(var.m_pdate)->month,
(var.m_pdate)->day);
5.CTime转换为CString
例:
m_begintime.Format("%Y-%m-%d");//2004-10-03
6.CString转换为CTime
//s="2004-10-5"
int first=s.Find('-');
int second=s.Find('-',first+1);
int year=atoi(s.Left(4));
int month=atoi(s.Mid(first+1,second-first+1));
int day=atoi(s.Mid(second+1,s.GetLength()-second-1));
CTime temp(year,month,day,0,0,0);
7.判断CString是否表示的正确日期格式
//判断是否为2004-01-13 ch 可代表其他分隔符
bool IsDate(CString str,char ch)
{
if(str.IsEmpty()) return false;
//日期分段
int first=str.Find(ch);
int second=str.Find(ch,first+1);
int year=atoi(str.Left(4));
int month=atoi(str.Mid(first+1,second-first+1));
int day=atoi(str.Mid(second+1,str.GetLength()-second-1));
//判断
if (year < 2000 || year >= 2010)
{
return false;
}
else if (month< 1 || month >12)
{
return false;
}
else if (day< 1 || day > 31)
{
return false;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
if(day > 30)
{
return false;
}
else
{
return true;
}
}
else if (month == '2')
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
if (day>29)
{
return false;
}
else
{
return true;
}
}
else if (day>28)
{
return false;
}
return true;
}
else
{
return true;
}
}
来源:安特软件培训http://user.qzone.qq.com/649166075
- CTime类使用小结
- CTime类小结
- CTime类使用大全
- CTime类format的使用
- CTime类format的使用
- CTime类及其变量使用
- CTime类及其变量使用
- CTime类format的使用
- CTime类及其变量使用
- CTime类format的使用
- CTime类format的使用
- CTime类format的使用
- ctime 使用
- CTime 使用
- CTime类format的使用【转贴】
- VC++中CTime类format的使用
- VC++中CTime类format的使用
- 使用CTime类 获取当前时间
- NSJSONSerialization
- 读取数据库中内容实现文件的下载
- 函数调用栈——初探!
- C语言---回调函数------------->解析
- javascript dom基础
- CTime类使用小结
- Exploring the /proc/net/ Directory
- Spring切入点
- 11级_Java_曹建波4.19 精通常用的Java类
- springaop术语概述及aop中常见通知的实现(10级学员 庞丽课堂总结)
- 采用链式存储实现,进栈、出栈操作
- 数据挖掘--挖掘频繁模式、关联和相关(1)
- MySQL 5.6 Replication - Enabling the Next Generation of Web & Cloud Services
- 秋天asp.net广告图片切换控件