全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
日期时间类变量的处理 C+编程时对日期时间类变量的处理一般采用 CTime 与 COleDateTime CTime 类 1) 获取当前时间。 CTime time; time = CTime:GetCurrentTime(); 2) 获取时间元素。 int year = time.GetYear() ; int month = time.GetMonth(); int day = time.GetDay(); int hour = time.GetHour(); int minute = time.GetMinute(); int second = time.GetSecond(); int DayOfWeek = time.GetDayOfWeek() ; Returns the day of the week based on local time; 1 = Sunday, 2 = Monday, to 7 = Saturday 3) 获取时间间隔。 CTimeSpan timespan(0,0,1,0); / days,hours,minutes,seconds timespan = CTime:GetCurrentTime() - time; 4) 把时间转换为字符串。 CString sDate,sTime,sElapsed Time ; sDate = time.Format(“%m/%d/%y“); /ex: 12/10/98 sTime = time.Format(“%H:%M:%S“); /ex: 9:12:02 sElapsed Time = timespan.Format(“%D:%H:%M:%S“); / %D is total elapsed days 要想知道更多的时间格式,参见 M F C 文档中的 strftime。 COleDateTime 类 1) 获得一年中的某一天。 COleDate Time datetime; datetime = COleDateTime:GetCurrentTime(); int DayOfYear = datetime.GetDayOfYear(); 2) 从文本串中读取时间。 COleDate Time datetime; datetime.ParseDateTime(“12:12:23 27 January 93“); 说明:CTime 和 COleDateTime 具有几乎同样的功能。然而 COleDateTime 允许 用户获得一年中的某一天(创建 Julian 日期的一种好方法),以及分析一个时间文本串。 与 CTime 相比, COleDateTime 的优点在于它支持 DWORD 变量。COleDateTime 使用的位数是双浮点的两倍,既然 CTime 只是简单地计算从 1970 年 1 月 1 日之后经过的 秒数, CTime 是无符号 long 类型,它的范围是 0-4 2 9 4 9 6 7 2 9 5; COleDateTime 是 double 类型,它占 64 位。 将界面录入的时间存入数据库的时间日期字段: 即如何把 COleDateTime 型 转化成为 _variant_t 型 COleVaraint var=COleDateTime(2001,11,25,0,12,34,56); _variant_t var1=var; 来源:电脑网络爱好者:/viewnews-24290.html ADO 数据库编程的例子 _variant_t var,varD; double time; COleDateTime timeD,timeD1; COleDateTimeSpan timespan2(0,0,90,0); CString strSQL,strTem,strTem1; varD=TAR.m_pRecordset-GetCollect(“DATATIME“); time=varD.date; timeD=time; /strTime=timeD.Format(“%y 年%m 月%d 日 %H:%M:%S“); strTem.Format(“%d-%d-%d %d:%d:%d“,timeD.GetYear(),timeD.GetMonth(),timeD.GetDay(),timeD.G etHour(),timeD.GetMinute(),timeD.GetSecond(); timeD1=timeD-timespan2; strTem1.Format(“%d-%d-%d %d:%d:%d“,timeD1.GetYear(),timeD1.GetMonth(),timeD1.GetDay(),timeD1. GetHour(),timeD1.GetMinute(),timeD1.GetSecond(); strSQL.Format(“select * from BOC where DATATIME between to_date(%s,yyyy-mm-dd hh24:mi:ss) and to_date(%s,yyyy-mm-dd hh24:mi:ss) order by DATATIME DESC“,strTem1,strTem); 说明:首先用 m_pRecordset-GetCollect()获取时间值,返回类型是 _variant_t,_variant_t 则有 date 的成员变量,但是是 double 类型的,这个 double 类型的数据可以直接赋值给 COleDateTime 类型,最后完成了从数据库时间类型到 VC+得时间类型的转化,COleDateTimeSpan 则可以对时间的间隔进行各种操作,但 获取总的秒数间隔是最准确,最有用的。 在用 SQL 语言进行查询时,to_date 函数可以把字符型的时间转化为 oracle 数据库 的日期型。例如:select * from CDUMP where DAT_END between to_date(2009-12-11 13:11:43,yyyy-mm-dd hh24:mi:ss)-1/24 and to_date(2009-12-11 13:11:43,yyyy-mm-dd hh24:mi:ss)。其中的 1/24 表示 一个小时,查询的是 2009-12-11 13:11:43 1 小时前的数据,需要注意的是前一个时 间一定要比后一个早。2009-12-11 13:11:43是字符型的。 例子: select DAT_END from CDUMP where (extract(year from DAT_END) between 2009 and 2009) and (extract(month from DAT_END) between 12 and 12) and (extract(day from DAT_END) between 11 and 11) and (to_char(DAT_END,HH24) between 12 and 13) select DAT_END from CDUMP where (extract(year from DAT_END) between %d and %d) and (extract(month from DAT_END) between %d and %d) and (extract(day from DAT_END) between %d and %d) and (to_char(DAT_END,HH24) between 12 and 13) select DATATIME from DMAIN_MIN where (extract(year from DATATIME) between 2009 and 2010) and (extract(month from DATATIME) between 11 and 12) and (extract(day from DATATIME) between 11 and 11) and (to_char(DATATIME,HH24) between 12 and 13) select count(*) from CDUMP versions DAT_END between to_date(2009-12-11 13:11:43,yyyy-mm-dd hh24:mi:ss) - intervel 1 minute and to_date(2009- 12-11 13:11:43,yyyy-mm-dd hh24:mi:ss) - intervel 31 minute select count(*) from CDUMP where DAT_END between to_date(2009-12- 11 13:11:43,yyyy-mm-dd hh24:mi:ss)-1/48 and to_date(2009-12-11 13:11:43,yyyy-mm-dd hh24:mi:ss) select count(*) from CDUMP where DAT_END between to_date(2009-12- 11 13:11:43,yyyy-mm-dd hh24:mi:ss)-1/24 and to_date(2009-12-11 13:11:43,yyyy-mm-dd hh24:mi:ss) select count(*) from CDUMP where DAT_END between to_date(2009-12- 11 13:11:43,yyyy-mm-dd hh24:mi:ss)-1/24 and to_date(2009-12-11 13:11:43,yyyy-mm-dd hh24:mi:ss) 查询 2009-12-11 13:11:43 1 小时前的数据量 select count(*) from CDUMP where DAT_END between to_date(2009-12- 11 13:11:43,yyyy-mm-dd hh2
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 气候健康公平的医院管理
- 2026年肾小管浓缩功能减退诊疗试题及答案(肾内科版)
- 睡眠呼吸暂停与心血管疾病专家共识(完整版解读)
- T∕CATAGS 59-2022 通 用航空器纤维增强复合材料湿法制造工艺
- 安宁疗护医疗决策标准统一的法律意义
- 2026届云南省玉溪市一中高三全真化学试题模拟试卷(16)含解析
- 河北省唐山二中2026届高考化学试题必刷模拟卷含解析
- 水凝胶模拟ECM引导巨噬细胞M2极化促皮肤再生
- 采购合同付款方式补充协议
- 26年泛癌种基因检测应用指南
- 2026年心理咨询师通关测试卷含完整答案详解(夺冠)
- 倒班人员作息健康管理培训
- 2026河南兴豫惠民职业技能培训学校有限公司市场化招聘15人笔试参考题库及答案解析
- 9.3 LLDPE物质安全资料表-2
- 2023年广东交通职业技术学院单招综合素质模拟试题及答案解析
- YC/T 88.1-2006烟草机械喂料机第1部分:型式与基本参数
- LY/T 2422-2015薇甘菊防治技术规程
- 真空预压传统式与直排式介绍ghg课件
- 大功率商用电磁灶使用说明书
- 工业机器人编程与实操期末试题
- 初中化学中考其他-学案离子(物质)的检验鉴别
评论
0/150
提交评论