赞
踩
android:textSize=“@dimen/text_size_16”
android:padding=“@dimen/dimen_10”/>
public class TextClockActivity extends AppCompatActivity {
private TextClock tc_timeText_12,tc_dateText_12,tc_timeText_24,tc_dateText_24;
private TextView tv_12hour,tv_24hour,tv_is24HourModeEnabled;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_textview_textclock);//加载布局文件
initView();
}
private void initView() {
tv_is24HourModeEnabled = findViewById(R.id.tv_is24HourModeEnabled);
tc_timeText_12 = findViewById(R.id.tc_timeText_12);
tc_dateText_12 = findViewById(R.id.tc_dateText_12);
tv_12hour = findViewById(R.id.tv_12hour);
//setTimeZone使用(UTC-7)无效,
//原因:源码未对UTC+(-)进行处理,下面有具体的源码分析
tc_timeText_12.setTimeZone(“America/Los_Angeles”);//有效
tc_dateText_12.setTimeZone(“America/Los_Angeles”);//有效
//tc_timeText_12.setTimeZone(“GMT+7:00”);//有效
//tc_dateText_12.setTimeZone(“GMT+7:00”);//有效
tc_dateText_12.setFormat24Hour(“HH:mm”);
tc_dateText_12.setFormat12Hour(“yyyy/MM/dd E”);
// EEEE:星期五 ;E/EE/EEE:周五;a:上午/下午
tc_dateText_12.setFormat24Hour(“yyyy年MM月dd日 EEEE aa HH:mm:ss”);
String format12 = “\n12小时模式格式:”+tc_timeText_12.getFormat12Hour();
format12 = format12+“\n24小时模式格式:”+tc_timeText_12.getFormat24Hour();
format12 = format12+“\n时区:”+tc_timeText_12.getTimeZone();
tv_12hour.setText(“Format:”+format12);
tc_timeText_24 = findViewById(R.id.tc_timeText_24);
tc_dateText_24 = findViewById(R.id.tc_dateText_24);
tv_24hour = findViewById(R.id.tv_24hour);
String format = “\n24小时模式格式:”+tc_timeText_24.getFormat24Hour();
format = format+“\n12小时模式格式:”+tc_timeText_24.getFormat12Hour();
format = format+“\n时区:”+tc_timeText_24.getTimeZone();
String timeZome =TimeZone
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。