MFC中 日期字符串的转换
2013-10-13 23:58
246 查看
一、将字符串2011-08-1800:00:00转换为字符串2011-8-18,通过以下的函数
CString DataDeleteZero(CString DATA)
{
CStringstrmonth,strday,stryear;
intyear=0,month=0,day=0;
year=atoi(DATA.Mid(0,4));
month=atoi(DATA.Mid(5,2));
day=atoi(DATA.Mid(8,2));
if(month<10)month=atoi(DATA.Mid(6,2));
if(day<10)day=atoi(DATA.Mid(9,2));
stryear.Format("%d",year);
strmonth.Format("%d",month);
strday.Format("%d",day);
DATA=stryear+"-"+strmonth+"-"+strday;
returnDATA;
}
二、MFC获得日期控件时间的cstring格式
变量定义:
CString strDate;
COleDateTime ole_time;
CTime c_time;
1、CString转换为COleDateTime
strDate = "2009-4-25 12:30:29";
ole_time.ParseDateTime(strDate);
2、COleDateTime转换为CString
strDate = ole_time.Format("%Y-%m-%d %H:%M:%S");
3、COleDateTime转换为CTime
SYSTEMTIME sys_time;
ole_time.GetAsSystemTime(sys_time);
c_time = CTime(sys_time);
4、CTime转换为COleDateTime
SYSTEMTIME sys_time;
c_time.GetAsSystemTime(sys_time);
ole_time = COleDateTime(sys_time);
5、CTime转换为CString
CTime Time;
Time.Format(“%Y-%m-%d”);
得到的是2011-08-18格式的字符串时间
Time.Format(“%y-%m-%d”);
得到的是11-08-18格式的字符串时间,年份和上面不一样了
Time.Format(“%Y-%#m-%#d”);
得到的是2011-8-18格式的字符串时间,可以把月份与日的“0”去掉
Time.Format("%Y-%m-%d %H:%M:%S");
得到的是2011-8-18 00:00:00格式的字符串时间
来源:http://blog.csdn.net/fuyanzhi1234/article/details/6736241
CString DataDeleteZero(CString DATA)
{
CStringstrmonth,strday,stryear;
intyear=0,month=0,day=0;
year=atoi(DATA.Mid(0,4));
month=atoi(DATA.Mid(5,2));
day=atoi(DATA.Mid(8,2));
if(month<10)month=atoi(DATA.Mid(6,2));
if(day<10)day=atoi(DATA.Mid(9,2));
stryear.Format("%d",year);
strmonth.Format("%d",month);
strday.Format("%d",day);
DATA=stryear+"-"+strmonth+"-"+strday;
returnDATA;
}
二、MFC获得日期控件时间的cstring格式
变量定义:
CString strDate;
COleDateTime ole_time;
CTime c_time;
1、CString转换为COleDateTime
strDate = "2009-4-25 12:30:29";
ole_time.ParseDateTime(strDate);
2、COleDateTime转换为CString
strDate = ole_time.Format("%Y-%m-%d %H:%M:%S");
3、COleDateTime转换为CTime
SYSTEMTIME sys_time;
ole_time.GetAsSystemTime(sys_time);
c_time = CTime(sys_time);
4、CTime转换为COleDateTime
SYSTEMTIME sys_time;
c_time.GetAsSystemTime(sys_time);
ole_time = COleDateTime(sys_time);
5、CTime转换为CString
CTime Time;
Time.Format(“%Y-%m-%d”);
得到的是2011-08-18格式的字符串时间
Time.Format(“%y-%m-%d”);
得到的是11-08-18格式的字符串时间,年份和上面不一样了
Time.Format(“%Y-%#m-%#d”);
得到的是2011-8-18格式的字符串时间,可以把月份与日的“0”去掉
Time.Format("%Y-%m-%d %H:%M:%S");
得到的是2011-8-18 00:00:00格式的字符串时间
来源:http://blog.csdn.net/fuyanzhi1234/article/details/6736241
相关文章推荐
- MFC日期字符串转换
- MFC日期字符串转换 .
- MFC日期与字符串相互转换
- 【js Date】时间字符串、时间戳转换成今天,明天,本月等文字日期
- 转:Oracle中的日期和字符串互相转换
- R语言处理日期值的数值和字符串之间的相互转换
- 如何把FOXPRO的日期类型转换为字符串类型!
- oracle不能直接用字符串匹配日期,字符串须转换为日期格式
- 4.4.2 将字符串转换为日期SimpleDateFormat类
- FLEX日期格式化处理和字符串转换
- Oracle to_char 日期转换字符串语句实例分享
- 将某个日期字符串转换为java.sql.Date的类型
- Oracle和Sql 日期格式与字符串格式相互转换
- javascript将字符串类型转换成日期进行比较
- MYSQL中日期与字符串间的相互转换
- JS 将字符串转换成日期类型注意
- javascript将字符串类型转换成日期进行比较
- javascript时间戳和日期字符串相互转换
- js把日期字符串转换成时间戳
- 两个字段拼接成字符串 转换成日期排序