摘: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"); //这里的格式也可以是别 ...
随机推荐
- 应对Memcached缓存失效,导致高并发查询DB的几种思路
原文地址: http://blog.csdn.net/hengyunabc/article/details/20735701 当Memcached缓存失效时,容易出现高并发的查询DB,导致DB压力骤然 ...
- ubuntu 设置静态IP GW
网卡配置静态IP地址 编辑文件/etc/network/interfaces: sudo vi /etc/network/interfaces 并用下面的行来替换有关eth0的行:# The prim ...
- Labeled Faces in the Wild 人脸识别数据集 部分训练数据
development training set Note: images displayed are original (non-aligned/funneled) images. match pa ...
- Python学习 —— 阶段综合练习三
Python学习 —— 阶段综合练习三 综合之前文件与文件夹操作的学习,做以下实例练习:(建议先不要看代码,自己先试着写:代码仅供参考,有多种实现方法) 1. 目录文件遍历(二层目录结构) 1). ...
- cocos2d-x v3.0各个环境下创建项目以及编译、执行官方DEMO
摘自:https://github.com/cocos2d/cocos2d-x/ 怎样创建一个新项目 How to start a new game Download the code from co ...
- iOS: 删除真机测试的Provisioning Profile后,在Code Singing中出现entitlements.plist文件无效,解决办法如下:
问题主题:method to The entitlements specified in your application’s Code Signing Entitlements file do no ...
- Django admin管理
admin的配置 admin是django强大功能之一,它能共从数据库中读取数据,呈现在页面中,进行管理.默认情况下,它的功能已经非常强大,如果你不需要复杂的功能,它已经够用,但是有时候,一些特殊的功 ...
- 无法对数据库'XXX' 执行删除,因为它正用于复制"的解决方
困扰二天的问题终于得以解决,貌似一个棘手的问题只要知道方法也似乎变得异常简单,记录此次的解决方法,避免遗忘. 无法对 数据库'UDS' 执行 删除,因为它正用于复制. (.Net SqlClient ...
- eclipse启动tomcat, http://localhost:8080无法访问的解决方案
问题:: tomcat在eclipse里面能正常启动,但在浏览器中访问http://localhost:8080/不能访问tomcat管理页面,且报404错误.同时其他项目页面也不能访问.访问的时候出 ...
- struts2-core-2.0.14更新到2.3.15
struts2-core-2.0.14更新到2.3.15 将低版本的struts2-core更新到最新版本2.3.15,更新jar包,有这个几个 1. struts2-core-2.0.14.jar ...