Android Question HH:MM to ticks ?

Colin Evans

Active Member
Licensed User
Longtime User
Hi, I've looked in the forum and I'm sure it's a quick fix but I can't find a way of changing a time entry of say 12:30 to ticks
Anybody know the answer please
 

DonManfred

Expert
Licensed User
Longtime User
12:30 ist missing a Date. How would you convert it to ticks without?

With a little bit of string methods you can extract the hours and minutes.
Then
B4X:
dim ticks as long = (12*DateTime.TicksPerHour)+(30*DateTime.TicksPerMinute)
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
12:30 ist missing a Date. How would you convert it to ticks without?

With a little bit of string methods you can extract the hours and minutes.
Then
B4X:
dim ticks as long = (12*DateTime.TicksPerHour)+(30*DateTime.TicksPerMinute)
Must be having a brain freeze, just added the date and now working wonderfully, thank you
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
DonManfred

Thought I'd sorted it but getting java.text.ParseException: Unparseable date: "05/01/2022 14:55"

newdate = "05/01/2022"
TimeFrom = "14:55"

DateTime.DateFormat = "dd/MM/yyyy hh:mm"

Dim tfrom As Long = DateTime.dateParse(newDate & " " & txtFrom.Text)

Any pointers on what I'm doing wrong
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
DateTime.DateFormat = "dd/MM/yyyy hh:mm"
Here is an example
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
    DateTime.TimeFormat = "HH:mm"   
    Dim newdate As String = "05/01/2022"
    Dim TimeFrom As String = "14:55"
    Log(DateTime.DateTimeParse(newdate,TimeFrom))

or:
B4X:
DateTime.DateFormat = "dd/MM/yyyy HH:mm"
    Dim newdate As String = "05/01/2022"
    Dim TimeFrom As String = "14:55"
    Log(DateTime.DateParse(newdate & " " & TimeFrom))
 
Last edited:
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Here is an example
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
    DateTime.TimeFormat = "HH:mm"  
    Dim newdate As String = "05/01/2022"
    Dim TimeFrom As String = "14:55"
    Log(DateTime.DateTimeParse(newdate,TimeFrom))

or:
B4X:
DateTime.DateFormat = "dd/MM/yyyy HH:mm"
    Dim newdate As String = "05/01/2022"
    Dim TimeFrom As String = "14:55"
    Log(DateTime.DateParse(newdate & " " & TimeFrom))
Can't believe it was something so stupid that I missed, I've been putting hh instead of HH, thank you Mahres (and DonManFred), I'd tried all the various formats I could think of but always put hh, I've slapped my wrists and moving on, thanks again
 
Upvote 0
Top