Have been playing with .. errrrr I mean, experimenting (posture improves) with b4a since last week. I've been impressed with it since I downloaded it! So much so that I bought it!! Used basic back in the day and this is a welcome second experience. Anyways enough ranting, my question follows.
How can I detect AM, PM and 24hr time? What I'm looking for something like this:
function functAMPM24hr returns 0 for 24hr clock, 1 for AM, or 2 for PM.
A code example would be great.
TIA
dep
===== "Making the simple complicated is commonplace; making the complicated simple, awesomely simple, that’s creativity.” --Charles Mingus
I didn't work with time in B4A but did you try something like this:
B4X:
Dim x As Int
x = DateTime.GetHour(now)
If x > 11 Then
ToastMessageShow("Now is PM (" &x& ")", False)
Else
ToastMessageShow("Now is AM (" &x& ")", False)
End If
Dim timeformat As String
timeformat = DateTime.DeviceDefaultTimeFormat
the string "timeformat" will contain the current set time format, for my 24hr setting it is "HH:mm:ss" for a 12hr setting it will be something like "h:mm a"
if you check SimpleDateFormat (Java 2 Platform SE v1.4.2) it explains all of the datetime possibilities.
The code in the previous post will only work if it is after midday.
Edward
Hi,
Having just tried changing my phone between 12hr and 24hr it does not give any different value for timeformat (so code I posted is no use) , I think the problem is the definition of 'DeviceDefaultTimeFormat'
DeviceDefaultTimeFormat As String [read only]
Returns the default time format based on the device selected language
so no matter time format you set your phone to the device format is still based on the language set.
The x in the code will be for 11:00 (24hr) will be 11 in the 12hr as well but the code thinks it is am so code is unreliable .
Edward
Hour = DateTime.GetHour(DateTime.Now)
Minutes = DateTime.GetMinute(DateTime.Now)
Seconds = DateTime.GetSecond(DateTime.Now)
If Hour < 12 Then Meridian = " AM"
If Hour = 12 Then Meridian = " PM"
If Hour = 0 Then
Hour = 12
Meridian = " AM"
End If
If Hour > 12 Then
Hour = Hour - 12
Meridian = " PM"
End If
TheTime = NumberFormat(Hour, 2, 0) & ":" & NumberFormat(Minutes, 2, 0) & ":" & NumberFormat(Seconds, 2, 0) & Meridian
Msgbox("The time is " & TheTime, "")
“A journey of a thousand miles must begin with a single step.” -– Lao Tzu
What are you waiting for? Be a b4a professional TODAY! Use code: bekfts when purchasing Basic4android Enterprise version and get 50% off!!!!Basic4android (click here)
Spot on Markus,
that did the trick. I must sit down some day and go thru the Android developers site there is a lot of info there Settings.System | Android Developers
Ticks value will be the same for am or pm just specify the