从Oralce数据库(第三方)读出的Date数据,怎么转为为time_t在MCF控件CListCtrl控件中正确的显示时间
2014-09-17 20:37
597 查看
首先,先看一个怎么输出time_类型数据例子:
strftime (char *s, size_t maxsize, const char *format, const struct tm *tp); //格式化输出函数#include <stdio.h> #include <time.h> int main () { static char str_time[100]; struct tm *local_time = NULL; time_t utc_time; utc_time = time (NULL); local_time = localtime(&utc_time); strftime(str_time, sizeof(str_time), "%Y-%m-%d,%H:%M:%S", local_time); printf ("Time: %s/n", str_time); return 0; }
运行输出:
./time
Time: 2009-08-14,13:59:22
原文:/article/10811694.html
现在我们来看本文的主题:
第一,连接数据库,///<初始化 StartOciLib(oci_error_callback ); ///<连接数据库 m_pConntion = OCI_ConnectionCreate(m_strDBConn.c_str(), m_strUserName.c_str(), m_strPwd.c_str(), OCI_SESSION_DEFAULT);
第二,解析数据库的字段UPDATE_TIME,
上面是数据库读出的字段格式,怎么才能对到MFC的ClistBox上面呢?
2,执行SQL语句
pState = OCI_StatementCreate(m_pConntion); if (NULL == pState) { return false; } ///<执行SQL,并返回结果集 pResult = ExecuteQuery_Select( pState, strSQL);
3.对返回的结果集进行解析
ClistBox的控件变量是:m_List_Cstrl.
///<解析字段: UPDATE_TIME 创建时间 <pre class="cpp" name="code"> while (OCI_FetchNext(pResult))
{
do{ if (OCI_IsNull2(pResult,"UPDATE_TIME")) { CString str25_6=""; str25_6.Format("第%d 行的字段Update_Time解析为空,设为-1", num ); m_List_Ctrl.SetItemText(num,row_num++,str25_6); } else { <strong><span style="color:#3366ff;"> OCI_Date * s_time =NULL; s_time = OCI_GetDate2(pResult, "UPDATE_TIME"); //从结果解对到OCI_Date类型的数据 static char str_time[100]; struct tm *local_time = NULL; time_t utc_time; utc_time = time (NULL); OCI_DateToCTime(s_time, NULL ,&utc_time); //把OCI_Date类型转换为time_t; local_time = localtime(&utc_time); //把time_t转换为 strut tm类型 strftime(str_time, sizeof(str_time), "%Y-%m-%d %H:%M:%S", local_time); //把strut tm类型通过strftime</span></strong>
<strong><span style="color:#3366ff;"> //使之按照"%Y-%m-%d %H:%M:%S格式显示</span></strong>
CString straa = ""; straa.Format("%s",str_time); m_List_Ctrl.SetItemText(num,row_num++,straa); //使之在CListBox显示
} while (0);
num++; }
上面蓝色的是类型转换的核心。
这样就可以完成从数据库date类型到MFC工程的时间类型显示了,希望能对你有所帮助。
相关文章推荐
- Date Time Picker时间控件只能显示日期或时分秒,我怎么才能让它在界面上同时显示出两者,并且保证点击下拉按钮时可编辑日期? 2010-11-24 19:47
- <问题解决>数据库date类型数据前端页面显示格式不正确问题
- 从后台返回的数据是个long型,如何转为正确的时间类型显示
- python访问数据库中时间类别的数据正确显示的问题
- 用date命令修改Linux系统的时间为什么无效?怎么才能正确显示
- 数据库中关于datetime、date 、time数据类型比较,及插入日期时间数据格式
- 将数据库中的数据通过 client 控件显示 (一个asp和javascript传参数的列子)
- Atlas入门-将普通控件升级为Atlas控件/使用listView显示数据库数据[视频]
- PHP中Date获取时间不正确怎么办
- 关于CListCtrl控件更新Item的闪烁问题和一次插入大容量数据的显示问题解决办法
- 在 DataGrid 控件中显示 SQL Server 数据库中的数据
- 【原创】Micrsoft Date and Time Picker Control (也就是MsCOMMCT2.OCX)控件在VC中不显示的问题及VC自带的Date Time Picker的用法
- 遇到日期型数据为空,却要插入数据库并正常显示出来,你怎么做
- [原创]读出数据库数据,控制显示长度!
- 数据绑定控件Repeater/GridView/DataList在前台显示正确的文本格式
- 读出数据库数据,控制显示长度
- 将数据库中的数据通过 client 控件显示 (一个asp和javascript传参数的列子)
- iBATIS查询ORALCE 数据库中Date数据类型
- 将数据库中的数据通过 client 控件显示 (一个asp和javascript传参数的列子)
- PHP中Date获取时间不正确怎么办