使用C ++将任何形式的日期时间字符串格式更改为美国日期时间格式 [英] Change any form of date time string format into US date time format using C++

查看:168
本文介绍了使用C ++将任何形式的日期时间字符串格式更改为美国日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



目前我正在处理71种日期时间格式,我希望所有这些格式都转换为美国日期时间格式。

例如:

输入:

日期时间格式1:

dddd,dd MMMM,yyyy h:mm: st tt

星期一,1992年10月17日4:32:28



日期时间格式2:

dd MMMM yyyy h:mm:ss tt

1992年10月17日4:32:28



日期时间格式3:

MM / DD / YYYY at HH:mm:ss

10/17/1992 at 4:32:28



以上格式必须转换并使用C ++打印成下面给定的格式

输出:dddd,MMMM dd,yyyy h:mm:ss tt(这是美国时间格式)

星期一,1992年10月17日4:32:28



嘿,我非常确定这段代码适用于美国和英国的系统。但同样不适用于西班牙语,荷兰语,法国系统



我尝试过:



目前我手动转换并插入美国格式的时间非常令人厌烦

Hi Guys,

currently i am dealing with 71 type of date time format, i want all this format to be converted into US date time format.
example:
input:
datetime format 1:
dddd, dd MMMM, yyyy h:mm:ss tt
monday,17 october 1992 4:32:28

datetime format 2:
dd MMMM yyyy h:mm:ss tt
17 october 1992 4:32:28

date time format 3:
MM/DD/YYYY at HH:mm:ss
10/17/1992 at 4:32:28

all above format must get converted and printed into below given format using C++
output : dddd, MMMM dd, yyyy h:mm:ss tt (this is US time format)
monday, october 17 1992 4:32:28

Hey i am very much sure that this code works well on US and UK system. but same doesnot works properly on spanish, dutch , france system

What I have tried:

Currently i am manually converting and inserting time into US Format which is very tiresome

推荐答案

您的问题是函数的典型用例 strptime 用于解析文本日期和 strftime 用于格式化输出。

strptime的代码也可以找到这里

剩下的就是一些代码编写。但请注意:您必须检测自己使用哪种模式。编写一些测试来检查解决方案的稳健性。
Your problem is the typical use case for the functions strptime for parsing the textual date and and strftime for formatting the output.
The code for strptime can be found also here.
The rest is some code writing. But be aware: you must detect yourself which pattern to use. Write some tests for check the robustness of your solution.


这篇关于使用C ++将任何形式的日期时间字符串格式更改为美国日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆