我已经建立了一个手表表盘,可以用两种不同的方式来报时。表盘有当前时区的12小时格式和格林威治时间的24小时格式。默认情况下,表盘只显示当前时区,这意味着我的时针在GMT时实际上只显示24小时格式的当前时区的时间。如何让手表同时显示多个时区?
发布于 2015-04-07 04:08:13
您可以创建2个具有不同时区的日历对象,然后使用以下对象:
Calendar germanyTime = new GregorianCalendar(TimeZone.getDefault());//your timezone
Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("GMT+0"));发布于 2015-04-08 18:50:32
我将给你一个例子,说明我是如何自动获取系统的时间格式的:
// variables
boolean is24Hour = false;
DateFormat df;
Calendar cal;
// get time format
is24Hour = df.is24HourFormat(context);
...
@Override
public void onDraw(Canvas canvas, Rect bounds) {
// always get a new instance in your onDraw()
cal = Calendar.getInstance();
// get the hours
if (is24Hour) {
format = new SimpleDateFormat("H");
return Integer.valueOf(format.format(cal.getTime()));
} else {
format = new SimpleDateFormat("h");
return (Integer.valueOf(format.format(cal.getTime()));
}
} https://stackoverflow.com/questions/29424640
复制相似问题