欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 用Time和Calendar獲取系統(tǒng)當(dāng)前時(shí)間源碼分享(年月日時(shí)分秒周幾)

 更新時(shí)間:2017年01月11日 14:13:36   作者:慌不擇食  
這篇文章主要介紹了Android 用Time和Calendar獲取系統(tǒng)當(dāng)前時(shí)間源碼分享,包括年月日時(shí)分秒周幾的源碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下

概述

用Time和Calendar獲取系統(tǒng)當(dāng)前時(shí)間(年月日時(shí)分秒周幾)

效果圖

源碼:

import android.app.Activity; 
import android.os.Bundle; 
import android.text.format.Time; 
import android.view.View; 
import android.widget.RelativeLayout; 
import android.widget.TextView; 
import java.util.Calendar; 
import butterknife.BindView; 
import butterknife.ButterKnife; 
import butterknife.OnClick; 
public class MainActivity extends Activity { 
 @BindView(R.id.tv_time) 
 TextView tvTime; 
 @BindView(R.id.activity_main) 
 RelativeLayout activityMain; 
 @BindView(R.id.tv_cal) 
 TextView tvCal; 
 Time time; 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_main); 
  ButterKnife.bind(this); 
  tvTime.setText("Time類"); 
  tvCal.setText("Calender類"); 
  initTime(); 
 } 
 private void initTime() { 
  time = new Time(); 
  time.setToNow(); 
 } 
 @OnClick({R.id.tv_cal,R.id.tv_time}) 
 public void onClick(View view) { 
  switch (view.getId()) { 
   case R.id.tv_time://點(diǎn)擊第一個(gè) 
    //月份是從0-11算的,所以顯示的話要+1 
    String times = time.year + "年" + time.month+1 + "月" + time.monthDay 
      + "日" + time.hour + "時(shí)" + time.minute + "分" + time.second + "秒" 
      + ":現(xiàn)在是一年中的第" + time.yearDay + "天"; 
    tvTime.setText(times); 
    break; 
   case R.id.tv_cal: 
    Calendar cal=Calendar.getInstance(); 
    String time_cal=""+cal.get(Calendar.YEAR)+"-"+cal.get(Calendar.MONTH)+1+"-"+cal.get(Calendar.DATE)+" " 
      +cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE); 
    tvCal.setText(time_cal); 
    break; 
  } 
 } 
 @Override 
 protected void onDestroy() { 
  super.onDestroy(); 
//  Unbinder unbinder=ButterKnife.bind(this); 
//  unbinder.unbind(); 
  ButterKnife.bind(this).unbind(); 
 } 
} 

布局就略了。。

這里獲取布局id和點(diǎn)擊事件用了(ButterKnife),可以參考:ButterKnife詳解

以上所述是小編給大家介紹的Android 用Time和Calendar獲取系統(tǒng)當(dāng)前時(shí)間源碼分享(年月日時(shí)分秒周幾),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論