摘: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"); //这里的格式也可以是别 ...
随机推荐
- Okam(奥卡姆):小程序开发框架
Okam(奥卡姆):小程序开发框架 Okam 是什么 `Okam` 一个面向小程序开发的开发框架,开发体验类 `Vue`.详情 Okam 对各小程序的支持情况 支持 百度小程序 支持 微信小程序 支持 ...
- 支持向量机通俗导论(理解SVM的三层境界) by v_JULY_v
支持向量机通俗导论(理解SVM的三层境界) 前言 动笔写这个支持向量机(support vector machine)是费了不少劲和困难的,原因很简单,一者这个东西本身就并不好懂,要深入学习和研究下去 ...
- ionic新手教程第八课-(加更)从无到有说Ionic、绘图说明MVC-U-S
这节课的内容,有些前面几节已经说过了. 公司这次给我一个任务,让我带一个没有编程基础的同事学习ionic. 今天是我跟他讲的第一课,晚上把讲的笔记整理了一下,认为还是挺适合零基础的朋友学习的. 有些前 ...
- 数学图形(1.40)T_parameter
不记得在哪搞了个数学公式生成的图形. vertices = t = to (*PI) r = 2.0 x = r*(*cos(t) - cos(*t)) y = r*(*sin(t) - sin(*t ...
- 融合libevent和protobuf
写了一个简单的例子,把libevent中的bufferevent网络收发服务和protobuf里面的序列反序列结合起来. protobuf文件message.proto: message PMessa ...
- django cookie and session
cookie和session 1.cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生. cookie的工作 ...
- Javascript-history.go()和history.back()的用法和区别
简单的说就是:go(-1): 返回上一页,原页面表单中的内容会丢失:back(): 返回上一页,原页表表单中的内容会保留. history.go(-1):后退+刷新 history.back():后退 ...
- [Unit Testing for Zombie] 06. Using Factory
FACTORIES Convert the zombies fixture to a Factory Girl Factory called :zombie. test/fixture/zombies ...
- 华为E392-u92在 linux 2.6.34 内核环境下支持
还是先说说思路吧.网关需要支持4G LTE网卡.如之前的操作,插上网卡后,usb-modeswitch 后没有产生对应的/dev/ttyUSB0-2. 所以ppp拨号脚本等无法工作.这里在ubuntu ...
- DD_belatedPNG
我们知道IE6是不支持透明的PNG的,这无疑限制了网页设计的发挥空间. 然而整个互联网上解决这个IE6的透明PNG的方案也是多不胜数,从使用IE特有的滤镜或是expression,再到javascr ...