Android Question Parse String to Ticks

hibrid0

Active Member
Licensed User
Longtime User
Hi I try to parse this string date format to ticks but get error.
The String I want to convert:
2018-07-20T05:00:00Z

With DateTime:
B4X:
DateTime.DateFormat = "dd/MM/yy"
DateTime.TimeFormat = "HH:mm:ss a"
Log(DateTime.DateParse("2018-07-20T05:00:00Z"))
Result: java.text.ParseException: Unparseable date: "2018-07-20T05:00:00Z"

With AHLocate:
B4X:
DateTime.DateFormat = "dd/MM/yy"
DateTime.TimeFormat = "HH:mm:ss a"
Log(DateTime.DateParse("2018-07-20T05:00:00Z"))
Result: java.lang.RuntimeException: Unable to parse date string


This date come from a remote db, on my device local db I use unix ticks.

Solved. Small function. I know my code is not the best. But I try to help.
B4X:
'Accept this format: 2018-07-20T05:00:00Z
Sub convertir_fecha_string_to_ticks(Fecha_remota As String) As String
    Dim Extractor_texto As String
    Extractor_texto=Fecha_remota
    Dim mes As String
    Dim dia As String
    Dim anyo As String
    dia = Extractor_texto.SubString2(8,10)
    mes = Extractor_texto.SubString2(5,7)
    anyo = Extractor_texto.SubString2(0,4)
   
    Return DateTime.DateParse(dia&"/"&mes&"/"&anyo)
   
End Sub
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
Hi I try to parse this string date format to ticks but get error.
The String I want to convert:
2018-07-20T05:00:00Z

With DateTime:
B4X:
Log(DateTime.DateParse("2018-07-20T05:00:00Z"))
Result: java.text.ParseException: Unparseable date: "2018-07-20T05:00:00Z"

With AHLocate:
B4X:
Log(DateTime.DateParse("2018-07-20T05:00:00Z"))
Result: java.lang.RuntimeException: Unable to parse date string

This date come from a remote db, on my device local db I use unix ticks
Take a look at this thread
https://www.b4x.com/android/forum/threads/convert-utc-to-ticks-and-vice-versa.36592/

Regards,
Walter
 
Upvote 0
Top