[Kotlin, JAVA]

밀리세컨드 단위 시간 구하기


간혹 파일명을 만든다던가하는 특수한 경우마다 중복이 일어나지 않기 위해 밀리세컨드 단위의 시간을 구해야하는 경우가 있습니다.

(키값이 중복되지 않는다는 점에선 가장 편한 방법일지도 모르겠지요. 주요 예로는 파일의 저장(영상, 사진) 등)

 

 - Kotlin 현재 시간 구하기

System.currentTimeMillis()

val testTime = "${System.currentTimeMillis()}"

 

 - JAVA 현재 시간 구하기

System.currentTimeMillis();

String testTime = String.valueOf(System.currentTimeMillis());

 

return type는 long형입니다.

 

 *** Reference : https://developer.android.com/reference/java/lang/System#currentTimeMillis()

 

System  |  Android 개발자  |  Android Developers

System public final class System extends Object java.lang.Object    ↳ java.lang.System The System class contains several useful class fields and methods. It cannot be instantiated. Among the facilities provided by the System class are standard input, stand

developer.android.com

 *** 소스에 문제가 있을 시 댓글달아주시면 최신화하도록 하겠습니다. 감사합니다

 

+ Recent posts