Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a string in the format
"thu,01 jan 2014 00:23:09 GMT"

I wanted to convert this into
01/01/2014 00:23:09.

is there any predefined methods to do this???
CString cookies= _T("Thu 05 Dec 2013 15:10:23 GMT"); 
COleDateTime dtTimecookie; dtTimecookie.Format(_T("%a %d %b %Y %X %Z")); 
dtTimecookie.ParseDateTime(cookies); 
int yy=dtTimecookie.GetYear();
int mm=dtTimecookie.GetMonth(); 
int dd=dtTimecookie.GetDay(); 
int hr=dtTimecookie.GetHour(); 
int min=dtTimecookie.GetMinute();
int sec=dtTimecookie.GetSecond();

CString dateStrcookie;
dateStrcookie.Format(_T("%d/%d/%d %d:%d:%d"),dd,mm,yy,hr,min,sec);

This is not working.
Posted
Updated 23-Jan-14 17:43pm
v3

1 solution

There is no standard function to do this, you need to write your own parsing routine to convert it to a tm structure as described in http://msdn.microsoft.com/en-us/library/kys1801b.aspx[^].
 
Share this answer
 
Comments
P Uday kishore 22-Jan-14 6:19am    
CString cookies= _T("Thu 05 Dec 2013 15:10:23 GMT");

COleDateTime dtTimecookie;

dtTimecookie.Format(_T("%a %d %b %Y %X %Z"));
dtTimecookie.ParseDateTime(cookies);


int yy=dtTimecookie.GetYear();
int mm=dtTimecookie.GetMonth();
int dd=dtTimecookie.GetDay();
int hr=dtTimecookie.GetHour();
int min=dtTimecookie.GetMinute();
int sec=dtTimecookie.GetSecond();

CString dateStrcookie;
dateStrcookie.Format(_T("%d/%d/%d %d:%d:%d"),dd,mm,yy,hr,min,sec);
Richard MacCutchan 22-Jan-14 6:59am    
Please use the Improve question link above, and show the full code that you are using, and the values of any input and output variables.

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