4

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

    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);
4

3 回答 3

3

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

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

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

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

于 2013-04-13T11:25:45.273 回答
1

尝试使用这个:

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];
于 2013-04-16T10:18:30.050 回答
0

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

于 2013-04-16T13:26:20.023 回答