Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 4-Apr-16 2:24am
v4
Comments
phil.o 30-Mar-16 3:22am    
Formatting a DateTime has to be done only on the user interface; at the data storage level, datetimes should be stored as the relevant datatype (datetime, datetime2, ...), not strings.

You did not tell much in your post, and you did not ask a formal question either. It will be difficult to get a specific answer without more precisions from your part.
Jochen Arndt 30-Mar-16 3:47am    
If you have a datetime string and want to convert it to a datetime value you need information about the used format. Without that information not all strings can be converted because format detections will not work for all possible variations. If the strings contain also day and/or month names, you will also have to support all possible languages. So this will be a quite extensive task and requires manual check afterwards for the cases where the detection is not distinct.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900