一、将字符串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

MFC中 日期字符串的转换的更多相关文章

  1. SpringMVC表单或Json中日期字符串与JavaBean的Date类型的转换

    SpringMVC表单或Json中日期字符串与JavaBean的Date类型的转换 场景一:表单中的日期字符串和JavaBean的Date类型的转换 在使用SpringMVC的时候,经常会遇到表单中的 ...

  2. SpringMVC中日期格式的转换

    解决日期提交转换异常的问题 由于日期数据有很多种格式,所以springmvc没办法把字符串转换成日期类型.所以需要自定义参数绑定.前端控制器接收到请求后,找到注解形式的处理器适配器,对RequestM ...

  3. 转:SpringMVC中日期格式的转换

    解决日期提交转换异常的问题 由于日期数据有很多种格式,所以springmvc没办法把字符串转换成日期类型.所以需要自定义参数绑定.前端控制器接收到请求后,找到注解形式的处理器适配器,对RequestM ...

  4. Java时间日期字符串格式转换大全

    import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @return 返回时间类型 ...

  5. mysql 日期 字符串 时间戳转换

    #时间转字符串 select date_format(now(), '%Y-%m-%d'); -02-27 #时间转时间戳 select unix_timestamp(now()); #字符串转时间 ...

  6. java中日期格式的转换和应用

    java中主要有3个类用于日期格式转换    DateFormat .SimpleDateFormat.Calendar SimpleDateFormat函数的继承关系: java.lang.Obje ...

  7. JS和vue中日期格式的转换

    1.获取当前时间: var now=new Date(); //Tue Oct 17 2017 18:08:40 GMT+0800 (中国标准时间) 获取当前时间的日期 new Date().getD ...

  8. java 日期字符串互相转换

    一.把日期转换成字符串 //获取当前时间  Date date = new Date();   //打印date数据类型  System.out.println(date.getClass().get ...

  9. json里的日期字符串 怎么 转换成 javascript 的 Date 对象?

    “/Date(1232035200000)/” 怎么转换成  javascript 的 Date 对象 做法:new Date(+/\d+/.exec(value)[1]); value就是json字 ...

随机推荐

  1. Leetcode 516.最长回文子序列

    最长回文子序列 给定一个字符串s,找到其中最长的回文子序列.可以假设s的最大长度为1000. 示例 1:输入: "bbbab" 输出: 4 一个可能的最长回文子序列为 " ...

  2. linux命令之grep、cut

    输入: ifconfig eth0 eth0表示主机的第一块网卡. 输出: eth0: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu inet 19 ...

  3. TOJ5272: 逆矩阵

    5272: 逆矩阵  Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByteTotal Submit: 11         ...

  4. Jquery版放大镜效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. BZOJ2395 [Balkan 2011]Timeismoney 【最小乘积生成树】

    题目链接 BZOJ2395 题意:无向图中每条边有两种权值,定义一个生成树的权值为两种权值各自的和的积 求权值最小的生成树 题解 如果我们将一个生成树的权值看做坐标,那么每一个生成树就对应一个二维平面 ...

  6. 洛谷P1175 表达式的转换

    P1175 表达式的转换 44通过 147提交 题目提供者该用户不存在 标签云端 难度提高+/省选- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 这题有毒 抄题解棒责五十! ...

  7. 0/1 knapsack problem

    Problem statement Given n items with size Ai and value Vi, and a backpack with size m. What's the ma ...

  8. ai相关

    学习资源 1.1 1.2 2.1 2.2 2.3 前置 octave sklearn python3 git 学习相关 link 定义 Field of study that gives comput ...

  9. 【转】Resharper上手指南

    原文发布时间为:2011-02-16 -- 来源于本人的百度文章 [由搬家工具导入] 我是visual studio的忠实用户,从visual studio 6一直用到了visual studio 2 ...

  10. [LeetCode] Search Insert Position 二分搜索

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...