在德国获得时间 – 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.getTime()); one_date.setText(tdate.toString()); one_day.setText(tday); 

正如我在这里建议的那样使用android.text.format.Time 。

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

 Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Europe/Berlin")); 

有关可用时区的列表: TimeZone.getAvailableIDs()

注意: SimpleDateFormat的语言环境用于读取/格式化该语言环境中的字符串 – 例如,使用德语语言环境将以德语打印月/日名称。 但它与时区无关。

试试这个:

 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];