标签:onclick format == color new t catch locale nts star
private void GainTime() {
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url=new URL("http://www.taobao.com");
URLConnection uc=url.openConnection();
uc.connect();
long id=uc.getDate();
Date date=new Date(id);
SimpleDateFormat formats=new SimpleDateFormat("网络时间:"+"HH:mm:ss", Locale.CHINA);
nowTime = formats.format(date);
Log.i("时间", date.getHours() + "时" + date.getMinutes() + "分"
+ date.getSeconds() + "秒" + "\n" + nowTime);
}catch (Exception e){
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}
}).start();
handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
time_texts.setText(nowTime);
if (nowTime==null||nowTime.equals("")){
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
time_texts.setText(sdf.format(new Date()) + "(" + "系统时间" + ")");
}
}
};
}
public void onClick(View view){
GainTime();
}
标签:onclick format == color new t catch locale nts star
原文地址:http://www.cnblogs.com/Dream0304/p/6964719.html