Android Question AM/PM thing changed to A.M. and P.M. (with dots)

Azam Memon

Member
Licensed User
I am using B4A 6.50 and suddenly, I am receiving A.M. and P.M. instead of simple AM and PM.

My simple code is:
B4X:
DateTime.TimeFormat = "hh:mm a"
Log(DateTime.Time(DateTime.Now))

and in Log i am getting:

10:41 p.m.

Hence my app is not parsing time like 05:00 pm. Is there any way to get AM/PM instead of A.M./P.M. ?

Note: My other android phones are working perfectly and showing "10:41 pm" but one smart phone is showing a.m. and p.m. And I want my app to work on that smart phone too.
 

Attachments

  • am_pm_issue.png
    am_pm_issue.png
    106.9 KB · Views: 385

Mahares

Expert
Licensed User
Longtime User
Hence my app is not parsing time like 05:00 pm. Is there any way to get AM/PM instead of A.M./P.M. ?
I just tested it on a device with B4A version 6.50 and it works the way it is supposed to, that is no periods.
but if your device has problems, you can do this to remove the periods:
B4X:
DateTime.TimeFormat = "hh:mm a"
    Dim MyTime As String
    MyTime = DateTime.Time(DateTime.Now)
    MyTime=MyTime.Replace(".","")
    Log($"Current time: ${MyTime}"$)
 
Upvote 0

MikeH

Well-Known Member
Licensed User
Longtime User
Or:

B4X:
StrTime = datetime.gethour & ":" & datetime.getminute
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
StrTime = datetime.gethour & ":" & datetime.getminute
I am afraid your code is not correct Mike. Not only you are missing the parameters like for gethour and getminute: DateTime.gethour(DateTime.Now) & ":" & DateTime.getminute(DateTime.Now), but also the problem is the hours returned are between 0 and 23 and the fellow wants AM/PM
 
Upvote 0

MikeH

Well-Known Member
Licensed User
Longtime User
I am afraid your code is not correct Mike. Not only you are missing the parameters like for gethour and getminute: DateTime.gethour(DateTime.Now) & ":" & DateTime.getminute(DateTime.Now), but also the problem is the hours returned are between 0 and 23 and the fellow wants AM/PM
I know, I was just pointing him in a helpful direction.... there are too many that expect too much to be done for them (not implying Azam is one).
 
Upvote 0

Azam Memon

Member
Licensed User
I actually want to parse time having am/pm information, my sample code is:

B4X:
DateTime.TimeFormat = "hh:mm a"
    Log(DateTime.Time(DateTime.Now))
   
    Dim data As String = "05:00 pm"
    Log(DateTime.Time(DateTime.TimeParse(data)))

This code is working on other phones except for few Samsung phones, I want this to work perfectly on all phones.

When I am using a.m. or p.m. (with periods), then it is working correctly on Samsung Galaxy J7 but not on others (see attachments).

B4X:
DateTime.TimeFormat = "hh:mm a"
    Log(DateTime.Time(DateTime.Now))
   
    Dim data As String = "05:00 p.m."
    Log(DateTime.Time(DateTime.TimeParse(data)))
 

Attachments

  • Screenshot 2017-02-27 15.50.54.png
    Screenshot 2017-02-27 15.50.54.png
    104.8 KB · Views: 280
  • Screenshot 2017-02-27 15.51.45.png
    Screenshot 2017-02-27 15.51.45.png
    77.5 KB · Views: 282
Upvote 0
Top