Solved

Help converting a string

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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