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
Solved

Help converting a string

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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