I got this kind of timestamp by parsing TCP packet 'Jan 27, 2017 16:58:15.688856000 India Standard Time'. How to convert this string to Datetime in C#?
-
Use Split to get parts, and then analize themSergio– Sergio2017-01-31 04:58:17 +00:00Commented Jan 31, 2017 at 4:58
-
splitting the string and parsing i can do.. is there any parseExact format (or) IFormatProvider for this kind of DateTime?Nanju– Nanju2017-01-31 05:00:04 +00:00Commented Jan 31, 2017 at 5:00
-
Well...No. For that string no. But you can use RegEx with enums to simplifySergio– Sergio2017-01-31 05:07:04 +00:00Commented Jan 31, 2017 at 5:07
Add a comment
|
2 Answers
use cliver
DateTime dt=new DateTime
if (!Cliver.DateTimeRoutines.TryParseDate('your text', Cliver.DateTimeRoutines.DateTimeFormat.UK_DATE, out dt))
{
//show message
}
According to this link you can simply try
string iString = "Jan 27, 2017 16:58:15.688856000 India Standard Time";
DateTime oDate = DateTime.ParseExact(iString, "MM-dd-yyyy HH:mm tt",null);
or
DateTime oDate = DateTime.ParseExact(iString, "MM-dd-yyyy",null);
After that if you want to format your own way you can try this link like
2017/02/01 or May 07, 2016