Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

익스피

안드로이 기기의 현재 시간 가져오기 API 본문

SW 개발/Andorid

안드로이 기기의 현재 시간 가져오기 API

악바리12 2019. 12. 30. 19:35

현재 기기의 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;