Android 는 Time 과 Calendar 로 시스템 의 현재 시간 원본 을 가 져 와 공유 합 니 다(년 월 일 시 분 초 몇 주)
Time 과 Calendar 로 시스템 현재 시간 가 져 오기(년 월 일 분 초 주 몇)
효과 도
원본 코드:
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://
// 0-11 , +1
String times = time.year + " " + time.month+1 + " " + time.monthDay
+ " " + time.hour + " " + time.minute + " " + time.second + " "
+ ": " + 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 와 클릭 이벤트 가 져 오기(ButterKnife)를 참고 할 수 있 습 니 다버터 나이프 상세 설명
위 에서 말 한 것 은 소 편 이 소개 한 안 드 로 이 드 용 Time 과 Calendar 가 져 오기 시스템 의 현재 시간 소스 코드 공유(년 월 일 시간 분 초 몇 주)입 니 다.여러분 에 게 도움 이 되 기 를 바 랍 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.소 편 은 제때에 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.