자바 현재시간 밀리세컨드 - jaba hyeonjaesigan millisekeondeu

주제>

자바에서 현재 시간을 가져와서 표현한다.

로그에서 현재 시간을 출력해 볼 때 쓰면된다.

시간 형식은 원하는 표현 방법을 사용하면 된다.

사용예>

시간 포맷을 아래와 같이 표현한다.

년-월-일 시간(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());

사용 예제>

System.out.println("현재 시간: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()));

Class SimpleDateFormat

1) 날짜와 시간 형식

자바 현재시간 밀리세컨드 - jaba hyeonjaesigan millisekeondeu
Date and Time Patterns

2) 사용방법

자바 현재시간 밀리세컨드 - jaba hyeonjaesigan millisekeondeu
Example

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 개요
  • 2 주의사항
  • 3 같이 보기
  • 4 참고

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 주의사항[ | ]

  • OS에 따라 자바 시간과 시스템시간이 서로 일치하지 않을 수 있다. https://technet.tmaxsoft.com/download.do?filePath=/nas/technet/technet/upload/kss/tnote/jeus/2014/01/&fileName=FILE-20140105-000038_140105150530_1.pdf

3 같이 보기[ | ]

  • 자바 System.nanoTime()
  • 자바 SimpleDateFormat
  • 자바 Util.currentTimeNanos()
  • 타임스탬프

4 참고[ | ]

  • https://www.tutorialspoint.com/java/lang/system_currenttimemillis.htm

원본 주소 "https://zetawiki.com/w/index.php?title=자바_System.currentTimeMillis()&oldid=773567"

분류:

  • Java
  • Java.text.SimpleDateFormat

수정 2021-04-17 생성 2017-04-12

편집자

문서 댓글 ({{ doc_comments.length }})

{{ zf.userName }}

로그인하시면 댓글을 쓸 수 있습니다.

{{ comment.name }} {{ comment.created | snstime }}

  • 분류 댓글:
  • {{cat.name.replace(/_/g,' ')}} ({{cat.cnt}})
  • {{comment.page_title}} {{comment.name}}