Как преобразовать дату в стандартную
Привет Ребята
В настоящее время у меня возникли некоторые проблемы с преобразованием дат в стандартную дату
Я построил этот метод, и все хорошо работает на моей машине dev, которая является Windows 7
когда я развертываю свою службу в UAT(Windows server 2012), я получаю систему ошибок.ArgumentOutOfRangeException: параметры Year, Month и Day описывают непредставимую дату-время.
не слишком уверен, что я делаю не так
Что я уже пробовал:
Public Function ConvertDateToStandard(ByVal Clientid As String, ByVal importtype As String, ByVal ImportDate As String) As String Try Dim ReturnDate As String = "" Dim DateFormat As String = "" Dim DateFormatSplit() As String Dim DateSplit() As String Dim CalenderDate() As String Dim Timesplit() As String Dim year As Integer = "1900" Dim Month As Integer = "01" Dim Day As Integer = "01" Dim Hour As Integer = 0 Dim Minute As Integer = 0 Dim second As Integer = 0 Dim DatePosition As String = "" Dim ConversionDate As New DateTime Dim calendarFormat() As String Dim timeformatstring() As String 'ImportDate = "Sun 29/01" DateSplit = ImportDate.Split(" ".ToCharArray) DateFormat = RRSGeneral.GetClientImportDateFormat(Clientid, importtype) If DateFormat = "" Then If DateSplit(0).Length = 4 Then DateFormat = "yyyy/MM/dd HH:mm:ss" Else DateFormat = "dd/MM/yyyy HH:mm:ss" End If End If If DateFormat.ToUpper.Contains("DDD") Then DateFormatSplit = DateFormat.Split(" ".ToCharArray) DateSplit = ImportDate.Split(" ".ToCharArray) calendarFormat = DateFormatSplit(1).Split("/".ToCharArray) CalenderDate = DateSplit(1).Split("/".ToCharArray) For count = 0 To calendarFormat.Count - 1 If calendarFormat(count).ToString.ToUpper.Contains("Y") Then year = CalenderDate(count) ElseIf calendarFormat(count).ToString.ToUpper.Contains("M") Then Month = CalenderDate(count) ElseIf calendarFormat(count).ToString.ToUpper.Contains("D") Then Day = CalenderDate(count) End If Next year = Date.Now.Year.ToString ConversionDate = New Date(CInt(year), CInt(Month), CInt(Day)) Dim conversionday As String = ConversionDate.ToString("ddd") If conversionday.ToString.ToUpper = DateSplit(0).ToString.ToUpper Then Else year = year - 1 ConversionDate = New Date(CInt(year), CInt(Month), CInt(Day)) If conversionday.ToString.ToUpper = DateSplit(0).ToString.ToUpper Then Else year = year - 1 ConversionDate = New Date(CInt(year), CInt(Month), CInt(Day)) End If End If Else DateFormatSplit = DateFormat.Split(" ".ToCharArray) If DateFormatSplit.Length > 1 Then If ImportDate.ToUpper.Contains(Environment.NewLine) Then ImportDate = ImportDate.Replace(vbCrLf, " ") End If DateSplit = ImportDate.Split(" ".ToCharArray) If DateFormatSplit(0).ToString.ToUpper.Contains("H") Then calendarFormat = DateFormatSplit(1).Split("/".ToCharArray) CalenderDate = DateSplit(1).Split("/".ToCharArray) Timesplit = DateSplit(0).Split(":".ToCharArray) For count = 0 To calendarFormat.Count - 1 If calendarFormat(count).ToString.ToUpper.Contains("Y") Then year = CalenderDate(count) ElseIf calendarFormat(count).ToString.ToUpper.Contains("M") Then Month = CalenderDate(count) ElseIf calendarFormat(count).ToString.ToUpper.Contains("D") Then Day = CalenderDate(count) End If Next timeformatstring = DateFormatSplit(0).Split(":".ToCharArray) For count = 0 To timeformatstring.Count - 1 If timeformatstring(count).ToString.ToUpper.Contains("H") Then Hour = Timesplit(count) ElseIf timeformatstring(count).ToString.ToUpper.Contains("M") Then Minute = Timesplit(count) ElseIf timeformatstring(count).ToString.ToUpper.Contains("S") Then second = Timesplit(count) End If Next ReturnDate = New Date(CInt(year), CInt(Month), CInt(Day), CInt(Hour), CInt(Minute), CInt(second)).ToString("dd MMM yyyy HH:mm:ss") Else calendarFormat = DateFormatSplit(0).Split("/".ToCharArray) CalenderDate = DateSplit(0).Split("/".ToCharArray) Timesplit = DateSplit(1).Split(":".ToCharArray) For count = 0 To calendarFormat.Count - 1 If calendarFormat(count).ToString.ToUpper.Contains("Y") Then year = CalenderDate(count) ElseIf calendarFormat(count).ToString.ToUpper.Contains("M") Then Month = CalenderDate(count) ElseIf calendarFormat(count).ToString.ToUpper.Contains("D") Then Day = CalenderDate(count) End If Next timeformatstring = DateFormatSplit(1).Split(":".ToCharArray) For count = 0 To timeformatstring.Count - 1 If timeformatstring(count).ToString.ToUpper.Contains("H") Then Hour = Timesplit(count) ElseIf timeformatstring(count).ToString.ToUpper.Contains("M") Then Minute = Timesplit(count) ElseIf timeformatstring(count).ToString.ToUpper.Contains("S") Then second = Timesplit(count) End If Next ReturnDate = New Date(CInt(year), CInt(Month), CInt(Day), CInt(Hour), CInt(Minute), CInt(second)).ToString("dd MMM yyyy HH:mm:ss") End If Else calendarFormat = DateFormatSplit(0).Split("/".ToCharArray) CalenderDate = DateSplit(0).Split("/".ToCharArray) 'Timesplit = DateSplit(1).Split(":".ToCharArray) For count = 0 To calendarFormat.Count - 1 If calendarFormat(count).ToString.ToUpper.Contains("Y") Then year = CalenderDate(count) ElseIf calendarFormat(count).ToString.ToUpper.Contains("M") Then Month = CalenderDate(count) ElseIf calendarFormat(count).ToString.ToUpper.Contains("D") Then Day = CalenderDate(count) End If Next ReturnDate = New Date(CInt(year), CInt(Month), CInt(Day), CInt(Hour), CInt(Minute), CInt(second)).ToString("dd MMM yyyy HH:mm:ss") End If End If 'MyReturnDate = New Date(CInt(year), CInt(Month), CInt(Day), CInt(Hour), CInt(Min), CInt(Seconds)) 'Return MyReturnDate.ToString("dd MMM yyyy HH:mm:ss") 'ReturnDate = Convert.ToDateTime(ConversionDate.ToString).ToString("dd MMM yyyy HH:mm:ss") Return ReturnDate
IsiR_19
Обнаружил, что файл проблемы обновлялся во время преобразования excel в CSV, а дата использовала культурную дату