주제> 자바에서 현재 시간을 가져와서 표현한다. 로그에서 현재 시간을 출력해 볼 때 쓰면된다. 시간 형식은 원하는 표현 방법을 사용하면 된다. 사용예> 시간 포맷을 아래와 같이 표현한다. 년-월-일 시간(24):분:초 yyyy-MM-dd HH:mm:ss 예로 2020년 09월 08일 오전 6시 0분 0초라면 표현 형식: 2020-09-08 06:00:00 아래와 같이 객체를 생성하면 된다. new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()); 사용 예제>
Class SimpleDateFormat 1) 날짜와 시간 형식 2) 사용방법 Class System public static long currentTimeMillis() : 현재 시간을 밀리세컨드로 리턴한다. public static 이므로 System.currentTimeMillis() 로 바로 가져다 쓸 수 있다. 출처> 오라클 자바 문서 Class SimpleDateFormat https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html Class System - currentTimeMillis public static long currentTimeMillis() Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds. See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC). Returns:the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#currentTimeMillis() 목차
1 개요[ | ]Java System.currentTimeMillis()
public class HelloWorld { public static void main(String [] args) { long millis = System.currentTimeMillis(); System.out.println(millis); // 1491968593191 } } import java.text.SimpleDateFormat; public class HelloWorld { public static void main(String [] args) { long nano = System.currentTimeMillis(); System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(nano)); // 2017-04-12 12:43:13.191 } } 2 주의사항[ | ]
3 같이 보기[ | ]
4 참고[ | ]
원본 주소 "https://zetawiki.com/w/index.php?title=자바_System.currentTimeMillis()&oldid=773567" 분류:
수정 2021-04-17 생성 2017-04-12 편집자 문서 댓글 ({{ doc_comments.length }}) {{ zf.userName }} 로그인하시면 댓글을 쓸 수 있습니다. {{ comment.name }} {{ comment.created | snstime }}
|