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
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AkshayPosted Dec 10, 2014, 4:59 AM
for that i use
var date='web sercive ref';
so result: Wed, 10 Dec 2014 14:19:42 +0530
Manish Kumar ChoudharyPosted Dec 10, 2014, 4:27 AM
DateTime dt = new DateTime();
DateTime.TryParse(x.Substring(0, x.LastIndexOf(' ')), out dt)
string result = dt.ToString("h:mmtt");
Wim SturkenboomPosted Dec 10, 2014, 4:24 AM
// 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'