Can anyone suggest simple and good timer picker?
Yes, I can! - the least trouble - just works?
Use this:
The other concept? I Always store my time "things" as date + time.
This will result in the ability to do time spans, and never worry about crossing the day boundary.
So, the time picker from above looks like this:
12 hour mode:
24 hour mode:
Now, as noted, I do adopt the concept of a date time.
Thus, with this code:
Sub Button1_Click
Dim dtTodayWithTime As Long = DateTime.Now
Dim dtToday As Long = GetTodayT
Dim PopTime As TimeDialog
PopTime.TimeTicks = dtTodayWithTime
If PopTime.Show("","Start Time","Ok","Cancel","",Null) = DialogResponse.POSITIVE Then
Dim pt As Period
pt.Initialize
pt.Hours = PopTime.Hour
pt.Minutes = PopTime.Minute
' save today date with time part
Dim MyResultDateTime As Long = DateUtils.AddPeriod(dtToday,pt)
' now for display
' 12 hour time
EditText1.Text = TicksToDate(MyResultDateTime,fTime)
' Date 24 hour time
EditText2.Text = TicksToDate(MyResultDateTime,fTime24)
' Date full text
EditText3.Text = TicksToDate(MyResultDateTime,fDateFull)
' Date full text with time
EditText4.Text = TicksToDate(MyResultDateTime,fDateFullT)
' Just the date
EditText5.Text = TicksToDate(MyResultDateTime,fDate)
End If
End Sub
Then I get this:
So from that one "time thing", I can extract the date or what ever i wish.
The code I have for TicksToTime is based on me define a set of "date formats".
If I am to to do anything with time, then I put these constants into my app - right from the get go:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public fDate As String = "MM/dd/yyyy"
Public fTime As String = "hh:mm:a" ' 12 hour AM/PM
Public fTime24 As String = "kk:mm" ' 24 hour
Public fDateTime As String = "yyyy-MM-dd HH:mm:ss"
Public fDateTimeSYS As String = "yyyy-MM-dd HH:mm:ss.000"
Public fDateFull As String = "EEEE, MMMM dd, yyyy"
Public fDateFullT As String = "EEEE, MMMM dd, yyyy " & fTime
End Sub
I VERY much had considered to store the ticks value. But sqLite, and even data I pull from SQL server etc. (as date time)? Well, they follow that standard format.
Thus, if I going to use that date/time value to interact with other systems - then best to stick to the android time format.
However, while dateutils is your friend?
I have two more routines - they let me convert from "ticks" to any of my above standard time formats.
Thus to same messy code - I have these 3 helper routines (that I used above in the sample code:
Sub DateToTicks(sDate As String, sFormat As String) As Long
' play nice - don't break anyones global format
Dim sOLD As String = DateTime.DateFormat
DateTime.DateFormat = sFormat
Try
Dim MyTicks As Long = DateTime.DateParse(sDate)
Catch
Log(LastException)
MyTicks = 0
End Try
DateTime.DateFormat = sOLD
Return MyTicks
End Sub
Sub TicksToDate(ticks As Long,sFormat As String) As String
' play nice - don't break anyones global format
Dim sOld As String = DateTime.DateFormat
DateTime.DateFormat = sFormat
Try
Dim sResult As String = DateTime.Date(ticks)
Catch
Log(LastException)
End Try
DateTime.DateFormat = sOld
Return sResult
End Sub
Public Sub GetTodayT As Long
' get today WITHOUT time portion
Dim tDay As Long = DateTime.Now
Return DateUtils.SetDate(DateTime.GetYear(tDay),DateTime.GetMonth(tDay),DateTime.GetDayOfMonth(tDay))
End Sub
So, with above routines - you are now ready to start coding, playing and having fun with date and time formats.
As noted, having and adopting Date + time formats WHEN dealing with time is nice, since then if you span midnight - or even MORE time, you do NOT care, and thus I have a screen like this based on above routines:
Note the FULL text date format in the upper right. And note the use of 12 hour formats - but STILL I cross midnight without issue.
So, having spent time on this?
Those built in dialogs - they work well, are quite easy to use, and you don't have to download or add anything more to B4A
Between dateutils, a few nice defined constants, and the DateToTicks, and TicksToDate? You quite much have a good ready to go framework in which to deal with time, dates and that of a nice time picker. The date picker in Dialogs2 is ALSO very nice - looks to be the standard Android picker, and again this helps for user learning curves and any user familiar having used Android.
Regards,
Albert D. Kallal
Edmonton, Alberta Canada