How to get Android date and time

Qbetechmark

Member
Licensed User
Longtime User
Does anyone know how to get android system's date and time, to be show in a label ?

My code is :

Dim now As Long
Dim dt As String
DateTime.DateFormat = "dd MMM yyyy"
dt = DateTime.Date(now)
DateTime.DateFormat = "hh:mm:ss"
dt = dt & CRLF & DateTime.Time(now)
Label4.Text = dt



Label4 is always showing 01-01-1970 07:00:00 , I'm expect it shows 07-Mar-2012 12:35.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Only by <2 minutes.

The good thing is you had the desire to help.
I love that about this place.
 
Upvote 0

Qbetechmark

Member
Licensed User
Longtime User
Thank you for your help.

Finally I solve my problem like this :

B4X:
Dim now As Long
Dim M, H As String

   DateTime.DateFormat = "dd MMM yyyy" 
   Label4.Text = DateTime.Date(DateTime.now) 
        'Because I don't know how to make DateFormat = "hh:mm", 
        'when I set like that, it is always shown seconds too.
        'So I use this code :
   H = DateTime.GetHour(DateTime.Now) 
   M = DateTime.GetMinute(DateTime.Now)
   Label5.Text = H & ":" & M
 
Last edited:
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
To show the time you need to use DateTime.TimeFormat = "hh:mm"

B4X:
DateTime.TimeFormat = "hh:mm"
Label4.Text = DateTime.Time(DateTime.Now)

regards, Ricky
 
Upvote 0
Top