Java 在德国获得时间-安卓

Java 在德国获得时间-安卓,java,android,Java,Android,无论用户的位置和当前设备时间如何,如何获取德国的当前时间 Calendar buttoncal = Calendar.getInstance(); String tdate = new SimpleDateFormat("dd.MM",Locale.GERMANY).format(buttoncal.getTime()); String tday = new SimpleDateFormat("EEEE",Locale.GERMANY).format(buttoncal

无论用户的位置和当前设备时间如何,如何获取德国的当前时间

    Calendar buttoncal = Calendar.getInstance();
    String tdate = new SimpleDateFormat("dd.MM",Locale.GERMANY).format(buttoncal.getTime());
    String tday  = new SimpleDateFormat("EEEE",Locale.GERMANY).format(buttoncal.getTime());


    one_date.setText(tdate.toString());
    one_day.setText(tday);

您可以指定需要使用的时区:

Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Europe/Berlin"));
有关可用时区的列表:
TimeZone.getAvailableIDs()

注意:
SimpleDataFormat
中的区域设置用于读取/格式化该区域设置中的字符串-例如,使用德语区域设置将以德语打印月/日名称。但它与时区无关。

尝试使用以下方法:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.GERMANY); 
Date date = new Date();
dateFormat.format(date);
您将获得格式为“yyyy-MM-dd HH:MM”的“日期”。然后,您可以使用.split()将返回的字符串格式拆分,并使用空格作为分隔符。比如:

String[] str_array = date.toString().split(" ");
String time = str_array[1];
改为使用。

我通过了TimeZone.getTimeZone(“欧洲/柏林”),但它仍然给出了当前设备时间,而不是柏林/德国的当前时间。我通过了TimeZone.getTimeZone(“欧洲/柏林”),但它仍然给出了当前设备时间,而不是柏林/德国的当前时间。