社区
数据库
帖子详情
CTime和CString怎么转换?
wpemily
2004-11-08 11:33:02
CTime -->CString可以用CTime::format()
反之,如果给一个CSting cstr="1999-9-6"
怎么把他转换为CTime对象CTime t呢?
主要是我用odbc连接数据库,因为字段里面又datetime类型,
而MFC自动在帮该类型字段绑定了相应的CTime对象,
而我存储数据的时候是像上面的cstr="1999-9-6"对象,
而不能转换为CTime对象!
谢谢!!
...全文
822
18
打赏
收藏
CTime和CString怎么转换?
CTime -->CString可以用CTime::format() 反之,如果给一个CSting cstr="1999-9-6" 怎么把他转换为CTime对象CTime t呢? 主要是我用odbc连接数据库,因为字段里面又datetime类型, 而MFC自动在帮该类型字段绑定了相应的CTime对象, 而我存储数据的时候是像上面的cstr="1999-9-6"对象, 而不能转换为CTime对象! 谢谢!!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
18 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
菜牛
2005-03-20
打赏
举报
回复
改用COleDateTime好了,只要把那个变量的类型改一下,不影响绑定,用COleDateTime::ParseDateTime()。
Featured
2005-03-20
打赏
举报
回复
可以很优雅地将CString转换成CTime
Featured
2005-03-20
打赏
举报
回复
sscanf可以的
http://community.csdn.net/Expert/topic/3690/3690591.xml?temp=.6320154
salaciouswolf
2005-03-19
打赏
举报
回复
mark
chuiyun
2005-03-18
打赏
举报
回复
不好意思,看错题了:)
chuiyun
2005-03-18
打赏
举报
回复
str = t.Format("%Y-%m-%d %H:%M:%S");
palmax
2005-03-18
打赏
举报
回复
mark
hushuangyan74
2005-03-18
打赏
举报
回复
直接用CTime的构造器就可以构造呀!
CTime(
int nYear,
int nMonth,
int nDay,
int nHour,
int nMin,
int nSec,
int nDST = –1 );
如CTime(2005,3,18,5,4,30);就建立了一个时间对象呀!
leechiyang
2004-12-10
打赏
举报
回复
用sscanf()读取年月日时分秒,然后CTime time(...)
不知效率是否比以下的方法高?如果需要大量转换可以试试.
strCString="2003-10-27 6:24:37"; //CString--->COleDateTime
COleVariant vtime(strCString);
vtime.ChangeType(VT_DATE);
COleDateTime time4=vtime;
COleDateTime time4; //COleDataTime--->CTime
SYSTEMTIME systime;
VariantTimeToSystemTime(time4, &systime);
CTime tm(systime);
wenjhua
2004-12-10
打赏
举报
回复
我也碰到了这样的问题,作等可行的办法!~~~~~
兄弟,我帮你顶了,不知道你解决这问题了没? 有的话能发个消息给我吗?
谢谢!~~~
ahaofang
2004-11-30
打赏
举报
回复
up
遇到过类似的问题,好象是用CString str.GetAt(i)获取年/月/日,然后用CTime time(0,0,0,0,0,0)jin进行转换.
Kudeet
2004-11-09
打赏
举报
回复
strCString="2003-10-27 6:24:37"; //CString--->COleDateTime
COleVariant vtime(strCString);
vtime.ChangeType(VT_DATE);
COleDateTime time4=vtime;
COleDateTime time4; //COleDataTime--->CTime
SYSTEMTIME systime;
VariantTimeToSystemTime(time4, &systime);
CTime tm(systime);
wave2050
2004-11-09
打赏
举报
回复
up
DentistryDoctor
2004-11-09
打赏
举报
回复
CTime::Format
or
CString::Format
蒋晟
2004-11-09
打赏
举报
回复
COleDateTime有ParseDateTime的
arvid_gs
2004-11-09
打赏
举报
回复
strCString="2003-10-27 6:24:37"; //CString--->COleDateTime
COleVariant vtime(strCString);
vtime.ChangeType(VT_DATE);
COleDateTime time4=vtime;
COleDateTime time4; //COleDataTime--->CTime
SYSTEMTIME systime;
VariantTimeToSystemTime(time4, &systime);
CTime tm(systime);
try876
2004-11-08
打赏
举报
回复
分解可以用
int nIndex, nYear, nMonth, nDay;
nIndex = cstr.Find("-");
nYear = atoi(cstr.Left(nIndex));
CString strRemain = cstr.Mid(nIndex + 1);
nIndex = strRemain.Find("-");
nMonth = atoi(strRemain.Left(nIndex));
同理,得到nDay
try876
2004-11-08
打赏
举报
回复
分解字符串为1999,9,6
然后用 CTime time(1999,9,6,0,0,0);
怎样将C
String
转换
成C
Time
类型
怎样将C
String
转换
成C
Time
类型
C
String
类型
转换
为C
Time
类型的函数
数据库中的日期型是C
String
,而对话框中的日期是C
Time
型,这个函数就是用来
转换
的
如何将C
Time
类型
转换
为C
String
如何将C
Time
类型
转换
为C
String
super_C
Time
C
Time
的各种
转换
子程序库。
super_C
Time
C
Time
的各种
转换
子程序库。和字符串的
转换
、和数字的
转换
等等 std::
string
getDate
String
(bool fgf);//获得表示当前日期的字符串,fgf表示是否需要分隔符 std::
string
get
Time
String
(bool fgf);//获得表示当前时间的字符串,fgf表示是否需要分隔符 C
String
getDateC
String
(bool fgf);//获得表示当前日期的字符串,fgf表示是否需要分隔符 C
String
get
Time
C
String
(bool fgf); std::
string
getDate
Time
String
(bool fgf);//获得表示当前日期和时间的字符串,fgf表示是否需要分隔符 std::
string
getDate
String
_from_C
Time
(C
Time
ct,bool fgf);//获得表示指定日期的字符串,fgf表示是否需要分隔符 std::
string
get
Time
String
_form_C
Time
(C
Time
ct,bool fgf);//获得表示指定时间的字符串,fgf表示是否需要分隔符 std::
string
getDate
Time
String
_from_C
Time
(C
Time
ct,bool fgf);//获得表示当前日期和时间的字符串,fgf表示是否需要分隔符 C
Time
get_date
Time
_from_u32(int date, int
time
); C
Time
get_date
Time
_from_
string
(std::
string
date, std::
string
time
);//字符串不带分隔符 C
Time
get_date
Time
_from_FGF
string
(std::
string
date, std::
string
time
); //字符串带分隔符
字符串
转换
日期C
String
to C
Time
一个把字符串
转换
成日期的函数,在网上找了好久没有找到类似的,后来问了一同学,搞定了。现传上来,以供新手借鉴。
数据库
4,018
社区成员
39,807
社区内容
发帖
与我相关
我的任务
数据库
VC/MFC 数据库
复制链接
扫一扫
分享
社区描述
VC/MFC 数据库
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章