Solved

Help converting a string

Posted on 2006-07-19
3
227 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

943 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

11 Experts available now in Live!

Get 1:1 Help Now