Android Question getTheTime Help

Mashiane

Expert
Licensed User
Longtime User
Hi

I would like some help with returning the datetime from this function in yyyy-MM-dd HH:mm format please. What I want to do is to return time at the city Africa/Johannesburg.

I came across this here..

B4X:
#If Java

import java.util.TimeZone;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit;

public String getTheTime(String place) {
  TimeZone zone = TimeZone.getTimeZone(place);
  DateFormat format = DateFormat.getDateTimeInstance();
  format.setTimeZone(zone);
  return(format.format(new Date()));
} 

public String[] getTimeZoneIDs() {

  String[] ids = TimeZone.getAvailableIDs();
  return ids;
}

#End If

and deviced this function.

B4X:
Sub SouthAfricanDateTime() As String
    Dim nativeMe As JavaObject
    Dim theTime As String
    Dim city As String = "Africa/Johannesburg"
    nativeMe.InitializeContext
    theTime = nativeMe.RunMethod("getTheTime",Array(city))
    Log(theTime)
    theTime = Replace(theTime,", ","-")
    theTime = Replace(theTime," ","-")
    Return theTime
End Sub

The results of the log are

B4X:
Oct 24, 2015 12:48:28 AM

How can I get this to be returned as yyyy-MM-dd HH:mm:ss format easily?
 
Top