zoukankan      html  css  js  c++  java
  • MFC中 日期字符串的转换

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

  • 相关阅读:
    关于断电即关闭的电路设计
    Python-29_常用模块复习
    Python-28_组合_继承_多态_封装_反射
    Python-27_面向对象
    Python-26_模块-02_python内置模板
    Python-25_模块-01_调用基本操作、路径
    Python-24_综合练习-01_函数_文件处理_解耦--查询功能
    Python-23_装饰器-04_练习---无参装饰器、有参装饰器
    Python-22_装饰器-03_解压序列
    Python-21_装饰器-02_装饰器实现
  • 原文地址:https://www.cnblogs.com/lxt287994374/p/3367453.html
Copyright © 2011-2022 走看看