Sub Activity_Create(FirstTime As Boolean)
DateTime.DateFormat = "yyyy-MM-dd"
'DateTime.TimeFormat = "hh:mm:ss"
Dim InputDate() As String = Regex.Split("T", "2021-01-08T11:39:00.000Z")
Dim t1 As Long = DateTime.DateParse(InputDate(0))
Dim t2 As Long = DateTime.TimeParse(InputDate(1))
Log(DateTime.Date(t1))
Log(DateTime.GetYear(t1))
Log(DateTime.GetMonth(t1))
Log(DateTime.GetDayOfMonth(t1))
Log(DateTime.Time(t2))
Log(DateTime.GetHour(t2))
Log(DateTime.GetMinute(t2))
Log(DateTime.GetSecond(t2))
End Sub
Normally, when you parse a date you are converting the date string into ticks, but if all you are interested in is breaking up the date string into its elements, in this case you do not need to use any of the datetime methods. Keep it simple like this:
B4X:
Dim d As String ="2021-01-08T11:39:00.000Z".Replace("-",":").Replace("T",":").Replace("Z","")
Dim str() As String=Regex.Split(":",d)
For i=0 To str.Length-1
Log(str(i)) 'logs all 6 components
Next
Thanks everyone for the help, I was confused about the symbols T and Z and how to handle them, they could just be ignored in the string or replaced with a blank.
I found at stackoverflow:
"The T is just a literal to separate the date from the time, and the Z means "zero hour offset" also known as "Zulu time" (UTC). If your strings always have a "Z" you can use:
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));