У меня проблема с преобразованием строки в нужный мне формат даты. Пример строки, которую я пытаюсь преобразовать, будет 215056081909. Я хотел бы преобразовать эту строку в 19.08.09 21: 50: 56.
Код, указанный ниже, - это то, что я пытаюсь использовать для процесса конвертации. Когда я запускаю код, я получаю сообщение об ошибке ниже, и я почти уверен, что это потому, что моя строка имеет временную часть в военном (24-часовом) времени. Может ли кто-нибудь помочь мне преобразовать строку в нужный мне формат?
Спасибо!
Error:
System.ArgumentOutOfRangeException was unhandled
Message="Index and length must refer to a location within the string. Parameter name: length"
ParamName="length"
Source="mscorlib"
StackTrace:
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex, Int32 length)
at GLTracker.PortManager.DoDataCollection(MessageType type, String msg)
at GLTracker.PortManager.comPort_DataReceived(Object sender, SerialDataReceivedEventArgs e)
at System.IO.Ports.SerialPort.CatchReceivedEvents(Object src, SerialDataReceivedEventArgs e)
at System.IO.Ports.SerialStream.EventLoopRunner.CallReceiveEvents(Object state)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
InnerException:
'Code:
Dim strDateTime as string = "215056081909"
Dim dTransDate As DateTime = Convert.ToDateTime(String.Format("{0}/{1}/{2} {3}:{4}:{5}", _
strDateTime.Substring(7, 2), _
strDateTime.Substring(9, 2), _
strDateTime.Substring(11, 2), _
strDateTime.Substring(0, 2), _
strDateTime.Substring(3, 2), _
strDateTime.Substring(5, 2)))