Solved

Help converting a string

Posted on 2006-07-19
3
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

622 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