Solved

Help converting a string

Posted on 2006-07-19
3
218 Views
Last Modified: 2010-04-24
I'm using C++/CLI.  Can anyone help me out with some code to convert the String "2006/07/13 12:00:00 PM" in to the String "20060713T1120000Z"
0
Comment
Question by:Lysandus
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
lakshman_ce earned 125 total points
ID: 17141284
Use DateTime class

.NET 2003 this can be done like this, try the same way in VS 2005

DateTime *pDateNow = &DateTime::Parse("2006/07/13 12:00:00 PM");
                         CultureInfo * MyCI = new CultureInfo(S"en-US", false);
                         DateTimeFormatInfo* myDTFI = MyCI -> DateTimeFormat;
                         String *dateFormat = myDTFI->UniversalSortableDateTimePattern;
                         dateFormat = dateFormat->Replace("-","");
                         dateFormat = dateFormat->Replace(":","");
                         dateFormat = dateFormat->Replace("'","");
                         dateFormat = dateFormat->Replace(" ","T");
                         String *newdate= pDateNow->ToString(dateFormat);
0
 
LVL 15

Expert Comment

by:lakshman_ce
ID: 17141286
newdate will have the required format "20060713T1120000Z"
0
 
LVL 1

Author Comment

by:Lysandus
ID: 17146554
Awesome, that worked! Thank you!

I had to change it to manage code for my application as follows:
DateTime ^pDateNow = DateTime::Parse("2006/07/13 12:00:00 PM");
            CultureInfo ^MyCI = gcnew CultureInfo("en-US", false);
            DateTimeFormatInfo^ myDTFI = MyCI->DateTimeFormat;
            String ^dateFormat = myDTFI->UniversalSortableDateTimePattern;
            dateFormat = dateFormat->Replace("-","");
            dateFormat = dateFormat->Replace(":","");
            dateFormat = dateFormat->Replace("'","");
            dateFormat = dateFormat->Replace(" ","T");
            String ^newdate= pDateNow->ToString(dateFormat);
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now