Android Question How can I Get Date & Time of Other Country ?

Adamdam

Active Member
Licensed User
Longtime User
Dear All,
Greetings

How can I Get Date & Time of Other Country ?
i.e. :
make this code to return back the date and time of other country not my current mobile clock
DateTime.DateFormat = "dd MMM yyyy"
Label1.Text = DateTime.Date(DateTime.now)

Thanks on advance.
 

aeric

Expert
Licensed User
Longtime User
Eg.
Kuala Lumpur, MY UTC+8
New York, USA UTC-5

19 Dec 2022 11:37:46
8
18 Dec 2022 22:37:46

B4X:
    DateTime.DateFormat = "dd MMM yyyy"
    DateTime.TimeFormat = "HH:mm:ss"
   
    Dim Now As Long = DateTime.Now ' Kuala Lumpur
    Log(DateTime.Date(Now) & " " & DateTime.Time(Now))
   
    Dim TZ As Double = DateTime.GetTimeZoneOffsetAt(Now)
    Log(TZ)
   
    DateTime.SetTimeZone(-5) ' New York
    Log(DateTime.Date(Now) & " " & DateTime.Time(Now))
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Similar to aeric but combining the date and time
B4X:
DateTime.DateFormat = "dd MMM yyyy HH:mm:ss"   
    Dim Now As Long = DateTime.Now ' Kuala Lumpur
    Log(DateTime.Date(Now))   
    Log(DateTime.GetTimeZoneOffsetAt(Now))
   
    DateTime.SetTimeZone(-5) ' New York
    Log(DateTime.Date(Now))
 
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
Similar to aeric but combining the date and time
B4X:
DateTime.DateFormat = "dd MMM yyyy HH:mm:ss"  
    Dim Now As Long = DateTime.Now ' Kuala Lumpur
    Log(DateTime.Date(Now))  
    Log(DateTime.GetTimeZoneOffsetAt(Now))
  
    DateTime.SetTimeZone(-5) ' New York
    Log(DateTime.Date(Now))
Thanks Mr.

Mahares​

Your code work well
Thanks a lot
 
Upvote 0

RobertCordon

New Member
Eg.
Kuala Lumpur, MY UTC+8
New York, USA UTC-5

19 Dec 2022 11:37:46
8
18 Dec 2022 22:37:46

B4X:
    DateTime.DateFormat = "dd MMM yyyy"
    DateTime.TimeFormat = "HH:mm:ss"
  
    Dim Now As Long = DateTime.Now ' Kuala Lumpur
    Log(DateTime.Date(Now) & " " & DateTime.Time(Now))
  
    Dim TZ As Double = DateTime.GetTimeZoneOffsetAt(Now)
    Log(TZ)
  
    DateTime.SetTimeZone(-5) ' New York
    Log(DateTime.Date(Now) & " " & DateTime.Time(Now))
Thank you sir.
 
Upvote 0
Top