khwarizmi Active Member Licensed User Longtime User Jan 8, 2021 #1 Hello all How can I parse a date-time in the formula : B4X: Copy 2021-01-08T11:39:00.000Z thanks
aeric Expert Licensed User Longtime User Jan 8, 2021 #2 kattah said: Hello all How can I parse a date-time in the formula : B4X: Copy 2021-01-08T11:39:00.000Z thanks Click to expand... I don’t get what you want. Is this input or output? Upvote 0
kattah said: Hello all How can I parse a date-time in the formula : B4X: Copy 2021-01-08T11:39:00.000Z thanks Click to expand... I don’t get what you want. Is this input or output?
khwarizmi Active Member Licensed User Longtime User Jan 8, 2021 #3 this is input, I want to parse this date string to year, month, day .. etc Upvote 0
M Mahares Expert Licensed User Longtime User Jan 8, 2021 #4 kattah said: How can I parse a date-time in the formula : Click to expand... To parse: 2021-01-08T11:39:00.000 You do this: Code: Copy DateTime.DateFormat="yyyy-MM-dd'T'HH:mm:ss.000" Log(DateTime.DateParse("2021-01-08T11:39:00.000")) not sure about your Z for your time zone in your date. Upvote 0
kattah said: How can I parse a date-time in the formula : Click to expand... To parse: 2021-01-08T11:39:00.000 You do this: Code: Copy DateTime.DateFormat="yyyy-MM-dd'T'HH:mm:ss.000" Log(DateTime.DateParse("2021-01-08T11:39:00.000")) not sure about your Z for your time zone in your date.
aeric Expert Licensed User Longtime User Jan 8, 2021 #5 B4X: Copy 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 Upvote 0
B4X: Copy 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
khwarizmi Active Member Licensed User Longtime User Jan 8, 2021 #6 thanks for help @aeric , @Mahares. Upvote 0
aeric Expert Licensed User Longtime User Jan 8, 2021 #7 kattah said: thanks for help @aeric , @Mahares. Click to expand... If my answer does helped you, you can give me a ? Like. If your question is solved, you can edit the thread title with prefix [SOLVED]. Upvote 0
kattah said: thanks for help @aeric , @Mahares. Click to expand... If my answer does helped you, you can give me a ? Like. If your question is solved, you can edit the thread title with prefix [SOLVED].
M Mahares Expert Licensed User Longtime User Jan 8, 2021 #8 kattah said: I want to parse this date string to year, month, day .. etc Click to expand... 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: Code: Copy 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 Upvote 0
kattah said: I want to parse this date string to year, month, day .. etc Click to expand... 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: Code: Copy 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
khwarizmi Active Member Licensed User Longtime User Jan 9, 2021 #9 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")); Or using Joda Time, you can use ISODateTimeFormat.dateTime(). " Upvote 0
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")); Or using Joda Time, you can use ISODateTimeFormat.dateTime(). "