Click here to Skip to main content
15,915,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..

I exported .ics(calendar) file from google calendar. Now i want to insert those events into database. while inserting we need to convert start time and end time to normal time.but i cant able to do that. how to convert it to Datetime format?

time is in this format "20120726T063000Z\r"

i need 07/26/2012 12:00:00PM
Posted

C#
string dateString, format;
DateTime result;
CultureInfo provider = CultureInfo.InvariantCulture;
// Parse date-only value with invariant culture.
dateString = "20120726T063000Z";
format = "yyyyMMddThhmmssssZ";
result = DateTime.ParseExact(dateString, format, provider);


Thanks,

Kuthuparakkal
 
Share this answer
 
Comments
07405 27-Aug-12 4:25am    
Thanks for that. it helped me. i am searching for this since two days.
Prasad_Kulkarni 27-Aug-12 7:54am    
Good work. My +5.
Kuthuparakkal 27-Aug-12 7:55am    
Thank you Prasad...
Use try Parse Exact method
C#
    DateTime localDate = DateTime.ParseExact("20120726T063000Z","yyyyMMdd\\Thhmmss\\Z",System.Globalization.CultureInfo.InstalledUICulture);

Console.WriteLine(localDate.ToString());


output will be
7/26/2012 6:30:00 AM
 
Share this answer
 
Here is one way to do it.

string strDate = "20120726T063000Z\r";
strDate = strDate.Replace("T", "").Replace("\r", "").Replace("Z", "");

DateTime MyDateTime;
MyDateTime = new DateTime();
MyDateTime = DateTime.ParseExact(strDate, "yyyyMMddHHmmss", null);


You can take a look at this article
Easy String to DateTime, DateTime to String and Formatting[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900