I have an app where the time is selected using the time dialog.
My Code:
B4X:
Sub GetTime(hh As Int, mm As Int)
td.Is24Hours=True
td.Hour=hh
td.Minute=mm
If td.Show("Select time", "", "Ok", "Cancel", "", Null) = DialogResponse.POSITIVE Then
TimeSet =(td.Hour-1) * DateTime.TicksPerHour + td.Minute * DateTime.TicksPerMinute
Log(td.Hour)
Log(DateTime.Time(TimeSet))
End If
End Sub
This code works but I don't understand why.
The value of td.Hour after selecting is correct but the value in TimeSet is one hour later???? This only seems to affect the hour, the minutes are correct. Adding the '-1' to td.Hour corrects this problem.
Can anyone tell me why this is required or have I made a mistake? Many Thanks.
Mark.
Dim ticks As Long = DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), _
DateTime.GetDayOfMonth(DateTime.Now), td.Hour, td.Minute, 0)
Date and time arithmetics are nice however they do not really work. Check DateTime.Date(TimeSet). It will be 1.1.1970. Luckily you tested your app when DST is active so you could see the issue.
Dim ticks As Long = DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now), _
DateTime.GetDayOfMonth(DateTime.Now), td.Hour, td.Minute, 0)
Date and time arithmetics are nice however they do not really work. Check DateTime.Date(TimeSet). It will be 1.1.1970. Luckily you tested your app when DST is active so you could see the issue.
I understand your code and you are correct about the date but I don't need the date. The dialog is only setting the time. Therefore your answer is good but not for my question - still confused.
Regards
Mark
I understand your code and you are correct about the date but I don't need the date. The dialog is only setting the time. Therefore your answer is good but not for my question - still confused.
Regards
Mark