Android Question Date and Time

gpbimal

Member
Hi! I'm new for b4a, i'm trying to get date and time in a string but unable.
here is my code

Dim DTStr As String
DateTime.DateFormat="mm-dd"
DTStr = DateTime.Date(DateTime.Now)
DateTime.TimeFormat="hh:mm:ss a"
DTStr = DTStr & " [" & DateTime.Time(DateTime.Now) & "]"

Please correct me
 
Please correct me
First of all, what does the string you want to achieve look like. Give an example. There are mistakes in your code. For example the date format you have is for minutes and day not month and day. Please use code tags when posting code
 
Upvote 0
Thank you William, problem is solved.

Code: Copy
    Dim DTStr As String
    DateTime.DateFormat="yyyy-MM-dd"
    DTStr = DateTime.Date(DateTime.Now)
    DateTime.TimeFormat="hh:mm:ss a"
    DTStr = DTStr & " [" & DateTime.Time(DateTime.Now) & "]"
    Log(DTStr)

Now the result is: 2022-09-27 [03:19:49 PM]
 
Upvote 0
Since now you are posting how you want your string to look like, you can simplify your code like this:
Code: Copy
DateTime.DateFormat="yyyy-MM-dd [h:mm:ss a]"
Dim DTStr As String = DateTime.Date(DateTime.Now)
Log(DTStr)  '2022-09-27 [10:59:36 AM]
Wow...Superb!
Thank you Mahares, I was stupid that I unable to share my requirement (exactly what I need)
 
Upvote 0
Back
Top