익스피
안드로이 기기의 현재 시간 가져오기 API 본문
현재 기기의 System time 없어 오는 API 및 방법을 기술한다.
1. system의 현재 밀리 세컨 time 값을 가져와 long 타입으로 이 값을 변수에 저장
2. 이 값을 Date type으로 변환
3. 날짜와 시간을 가져오고 싶은 형태로 가져와 사용하면 끝
ex)
1. long currentMillsec = System.currentTimeMillis();
2. Date curentDate = new Date(currentMillsec);
3. SimpleDateFormat currnetTimeFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String currentTime = currnetTimeFormat .format(curentDate);
그리고 아래 헤드 Import 가 필요하다. 안드로이드 스튜디오에서 Alt+Enter 키로 자동 추가할수있다.
import java.text.SimpleDateFormat;
import java.util.Date;