Convert Wed, 10 Dec 2014 14:19:42 +0530 to 02:19pm
i want to convert Wed, 10 Dec 2014 14:19:42 +0530 to time 02:19pm
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Wim SturkenboomRank #2,527 · 554 reputationPosted Dec 9, 2014, 11:24 PM EST
// find the last space
int position = x.LastIndexOf(' ');
// remove the timezone info
x = x.Substring(0, position);
// create datetime object
DateTime dt = new DateTime(0);
// try to parse input string
if (DateTime.TryParse(x, out dt))
{
// get time in desired format
string result = dt.ToString("h:mmtt");
}
else
{
// error in format
}
I suggest you read up on string functions and on 'Custom Date and Time Format Strings'
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Dec 9, 2014, 11:27 PM EST
DateTime dt = new DateTime();
DateTime.TryParse(x.Substring(0, x.LastIndexOf(' ')), out dt)
string result = dt.ToString("h:mmtt");
Akshay82 reputationPosted Dec 9, 2014, 11:59 PM EST
for that i use
var date='web sercive ref';
so result: Wed, 10 Dec 2014 14:19:42 +0530