摘:C++日期时间与字符串间的转换
|
VC6中 CString sTime = _T("2007-10-26 13:20:30"); char *charTime = (LPSTR)(LPCTSTR)sTime; CString sFormat = _T("%d-%d-%d %d:%d:%d"); char *charFormat = (LPSTR)(LPCTSTR)sFormat; int nYear; int nMonth; int nDate; int nHour; int nMin; int nSec; stscanf(charTime,charFormat,&nYear,&nMonth,&nDate,&nHour,&nMin,&nSec); CTime t(nYear,nMonth,nDate,nHour,nMin,nSec); CString s = t.Format(_T("%Y年%m月%d日%H时%M分%S秒")); VC2005中 不含中文格式 stscanf(charTime,charFormat,&nYear,&nMonth,&nDate,&nHour,&nMin,&nSec); CString sTime = _T("2007-10-26 12:40:10"); TCHAR *charTime = (TCHAR*)(LPCTSTR)sTime; CString sFormat = _T("%d-%d-%d %d:%d:%d"); TCHAR *charFormat = (TCHAR*)(LPCTSTR)sFormat; int nYear; int nMonth; int nDate; int nHour; int nMin; int nSec; _stscanf(charTime,charFormat,&nYear,&nMonth,&nDate,&nHour,&nMin,&nSec); CTime t(nYear,nMonth,nDate,nHour,nMin,nSec); CString s = t.Format(_T("%Y-%m-%d %H:%M:%S")); 含中文格式 要包含#include <locale.h> CString sTime = _T("2007-10-26 12:40:10"); TCHAR *charTime = (TCHAR*)(LPCTSTR)sTime; CString sFormat = _T("%d-%d-%d %d:%d:%d"); TCHAR *charFormat = (TCHAR*)(LPCTSTR)sFormat; int nYear; int nMonth; int nDate; int nHour; int nMin; int nSec; _stscanf(charTime,charFormat,&nYear,&nMonth,&nDate,&nHour,&nMin,&nSec); CTime t(nYear,nMonth,nDate,nHour,nMin,nSec); _tsetlocale(LC_ALL,_T("Chinese-simplified")); //本地化 CString s = t.Format(_T("%Y年%m月%d日%H时%M分%S秒")); |
摘:C++日期时间与字符串间的转换的更多相关文章
- Java开发笔记(四十四)本地日期时间与字符串的互相转换
之前介绍Calendar的时候,提到日历实例无法直接输出格式化后的时间字符串,必须先把Calendar类型转换成Date类型,再通过格式化工具SimpleDateFormat获得字符串.而日期时间的格 ...
- python 日期、时间处理,各种日期时间格式/字符串之间的相互转换究竟是怎样的?
模块函数说明 ''' date 日期对象,常用的属性有year,month,day time 时间对象,常用的属性有hour,minute,second,毫秒 datetime 日期时间对象,常用的属 ...
- c#日期与字符串间的转换(转)
1.日期转字符串(转载) 在编程中经常要用到将日期变量转换为字符串的情况,而且不同的时候希望转换成不同格式的字符串 下面是一些常用的转换及转换结果: (查看格式说明) 以日期为例: 2009-09-0 ...
- sql server日期时间转字符串
一.sql server日期时间函数Sql Server中的日期与时间函数 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基 ...
- sql server日期时间转字符串(转)
一.sql server日期时间函数Sql Server中的日期与时间函数 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基 ...
- sql server 日期时间与字符串的转换
一.sql server日期时间函数Sql Server中的日期与时间函数 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基 ...
- mysql日期/时间转换为字符串
将日期时间2016-05-13 16:07:50转化为字符串20160513 date_format select phone, date_format(time, '%Y%m%d%H%i%s') ...
- Java 日期时间与unix时间戳之间转换
日期时间 <--> 时间戳 java.time 包提供的新的日期和时间API LocalDateTime: 本地日期时间类 ZoneId: 时区类 ZonedDateTime: 带时区 ...
- 字符串类型日期时间转换为Date类型解析转换异常java.text.ParseException: Unparseable date: “2019-09-27T18:31:31+08:00”
错误的写法: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //这里的格式也可以是别 ...
随机推荐
- 使用ScrapySharp快速从网页中采集数据
ScrapySharp是一个帮助我们快速实现网页数据采集的库,它主要提供了如下两个功能 从Url获取Html数据 提供CSS选择器的方式解析Html节点 安装: ScrapySharp可以直接从Nug ...
- JavaScript中数组的各种操作方法
[监测数组] 使用instanceof操作符,进行检测 ar arr = [1,2,3]; // arr = '非非'; if(arr instanceof Array){ console.log(' ...
- VS2010程序打包操作(超详细的)转
1. 在vs2010 选择“新建项目”----“其他项目类型”----“Visual Studio Installerà“安装项目”: 命名为:Setup1 . 这是在VS2010中将有三个文件夹, ...
- Google Chrome 39.0.2171.71 正式发布
Google Chrome,又称Google浏览器,是一个由Google(谷歌)公司开发的网页浏览器.该浏览器是基于其他开源软件所撰写,包括WebKit,目标是提升稳定性.速度和安全性,并创造出简单且 ...
- C# 怎么获取所有打开的窗体
FormCollection collection = Application.OpenForms; foreach(Form form in collection){ if(form.Visi ...
- weblogic清理缓存后重启
清理缓存步骤如下: 1.前置条件:停止服务 2.找到下面3个目录,然后将里面的文件删除即可: ……/user_projects/domains/base_domain/servers/AdminSer ...
- telnet用法 测试端口号
Telnet是进行远程登录的标准协议和主要方式它为用户提供了在本地计算机上完成远程主机工作的能力.可以用telnet命令来测试端口号是否正常打开还是关闭状态. 工具/原料 电脑 cmd命令 方法/步骤 ...
- 《Linux兵书》
<Linux兵书> 基本信息 作者: 刘丽霞 杨宇 丛书名: 程序员藏经阁 出版社:电子工业出版社 ISBN:9787121219924 上架时间:2014-1-13 出版日期:20 ...
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space
在Eclipse 调试 springside showcase项目中,tomcat报异常 Exception in thread "RMI TCP Connection(idle)" ...