



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
日期时间类变量的处理 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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO/IEC 29168-2:2025 EN Information technology - Open systems interconnection - Part 2: Procedures for the object identifier resolution system operational agency
- 门急诊科年终总结
- 年终总结汇报
- 尤袤《送赵子直帅蜀得须字二首(其二)》古诗鉴赏试题答案及解析
- 防雷防汛安全培训
- 如何制作车型培训
- 喷气织机技术解析
- 2026届山东省威海市化学九年级第一学期期中检测试题含解析
- 人事薪酬月度工作总结
- 2026届吉林省大安县联考九年级化学第一学期期末教学质量检测试题含解析
- MOOC 理解马克思-南京大学 中国大学慕课答案
- 全科医疗教学查房
- 保护牙齿少吃糖公开课课件
- 移植前打达菲林的方案
- 职业病危害因素评价与检测课件
- 财务报销培训课件
- 2024年纺织服装培训资料
- 安全风险预警与应急响应的能力评估
- 新媒体运营 课程标准
- 中国糖尿病肾病指南
- 西师大版五年级音乐上册 第一单元《走街街》 课件走 街 街
评论
0/150
提交评论