Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The idea of splitting the string is on the right track, but substring is slow. Whenever I split a string, I use the character accessor. yyyyMMddTHHmmssfff Disclaimer: T</p> <pre><code>public class DateParser1 { private static System.String DateFormat="yyMMddTHHmmssfff"; public static System.DateTime GetDate(System.String SourceString, int Offset=0) // Offset eliminates need for substring { int Year=0; int Month=0; int Day=0; int Hour=0; int Minute=0; int Second=0; int HourOffset=0; int MS=0; if(SourceString.Length+Offset&lt;DateFormat.Length) throw new System.Exception(System.String.Format("Date Too Short {0} For {0}",SourceString.Substring(Offset),DateFormat)); for(int i=0;i&lt;DateFormat.Length;i++) { System.Char c=SourceString[Offset+i]; switch(DateFormat[i]) { case 'y': Year=Year*10+(c-'0'); break; case 'M': Month=Month*10+(c-'0'); break; case 'd': Day=Day*10+(c-'0'); break; case 'T': if(c=='p'||c=='P') HourOffset=12; break; case 'h': Hour=Hour*10+(c-'0'); if(Hour==12) Hour=0; break; case 'H': Hour=Hour*10+(c-'0'); HourOffset=0; break; case 'm': Minute=Minute*10+(c-'0'); break; case 's': Second=Second*10+(c-'0'); break; case 'f': MS=MS*10+(c-'0'); break; } } if(Year&gt;30) //Change For Your Business Rules { Year+=1900; } else { Year+=2000; } try { return new System.DateTime(Year,Month,Day,Hour+HourOffset,Minute,Second,MS); } catch(System.Exception) { throw new System.Exception(System.String.Format("Error In Date: {0}/{0}/{0} {0}:{0}:{0}.{0} - {0} {0}",Year,Month,Day,Hour+HourOffset,Minute,Second,MS,DateFormat,SourceString.SubString(Offset,DateFormat.Length))); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload