Android的 - 获取欧洲/柏林当前时间,无论设备的时间和地点? [英] Android - Getting Europe/Berlin current time regardless of device time and location?

查看:398
本文介绍了Android的 - 获取欧洲/柏林当前时间,无论设备的时间和地点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code。我米的电视指南应用为德国电视频道工作,因此我需要在德国当前的时间,无论设备的时间和地点。

 日历buttoncal = Calendar.getInstance(TimeZone.getTimeZone(欧洲/柏林));
串tdate =新的SimpleDateFormat(dd.MM,Locale.GERMANY).format(buttoncal.getTime());
串tday =新的SimpleDateFormat(EEEE,Locale.GERMANY).format(buttoncal.getTime());
one_date.setText(tdate.toString());
one_day.setText(tday);


解决方案

每当人们推荐使用日历在Android上,我就来爬出我的小藏身之处,并告诉他们,请考虑 android.text.format.Time 代替因为它是日常使用简直就是完美。更轻便和实用需求的地步。

 时间deTime =新时代(欧洲/柏林);
deTime.setToNow();
deTime.format(...);

有关格式,请参见 http://linux.die.net/man/3/strftime 。如果我是作者,我不使用固定德国本地格式,而是善待所有有志于德国电视的外国人和尊重设备的语言环境,像这样:

  deTime.format(%C);

This is my code. I m working on TV guide app for german tv channels therefore I need to have current time in germany regardless of device time and location

Calendar buttoncal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Berlin"));
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);

解决方案

Whenever people recommend using Calender on Android, I'll come creeping out of my tiny hiding place and tell them to please consider android.text.format.Time instead because it's simply perfect for everyday use. Much more lightweight and to the point of practical needs.

Time deTime = new Time("Europe/Berlin");
deTime.setToNow();
deTime.format("...");

For the format, see http://linux.die.net/man/3/strftime. If I'd be the author, I'd not use fixed German local format, but rather be kind to all the foreigners interested in German TV and respect the device's locale, like so:

deTime.format("%c");

这篇关于Android的 - 获取欧洲/柏林当前时间,无论设备的时间和地点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆