Android Question AHLocale GetRelativeTimeSpanString with a DateTime Value

Alexander Stolte

Expert
Licensed User
A few days ago, i implemented the library of @corwin42 with the name ahlocale.

My Problem was, i had a DateTime value from the database and I had to split it up and adjust it.

As I have solved this, I will show here times:

My Value from the database looks so: 2017-07-25 13:00:00

Now to the code:

B4X:
'from the lib.  AHLocale
Dim du As AHDateUtils

'our DateTime value
Dim DateString AsString = "2017-07-25 13:00:00"

'split the string into 2 parts
Dim parts() AsString = Regex.Split("\s", DateString) '\s = whitespace character

'We must adjust the DateFormat
DateTime.DateFormat = "yyyy-MM-dd"'

'Declare a variable, so we can the splittet value, put it in after parsing
Dim Ticks As Long = DateTime.DateTimeParse(parts(0), parts(1))
   
'now we can call:
    lbl_mylabel.Text = du.GetRelativeTimeSpanString(Ticks , DateTime.Now, DateTime.TicksPerMinute, 0)

and it works now without problems.

i hope it helps you.
 
Last edited:

DonManfred

Expert
Licensed User
Upvote 0

Erel

Administrator
Staff member
Licensed User
The tutorials forum is mainly for tutorials.
It is better to post small code examples in the code snippets forum.

The code is not clear enough. What is du? What is du.GetRelativeTimeSpanString?

Why is a ticks variable named tformat?

Also note that the thread prefix [AHLocale] is not a standard prefix.
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Task: Parse a time string such as: 2017-07-25 13:00:00

Code:
B4X:
Dim DateString As String = "2017-07-25 13:00:00"
Dim parts() As String = Regex.Split("\s", DateString) '\s = whitespace character
DateTime.DateFormat = "yyyy-MM-dd" 'uppercase MM!
Dim Ticks As Long = DateTime.DateTimeParse(parts(0), parts(1))
'test it
Log($"$DateTime{Ticks}"$)
 
Upvote 0
Top