목차
java.util.Date 생성자
java.util.Date의 메소드
Conclusion
Java java지도 시간 java.util.날짜

java.util.날짜

Aug 30, 2024 pm 03:49 PM
java

Java의 날짜와 시간은 java.util.Date 클래스라는 클래스로 표현됩니다. 이 클래스는 Java에서 시간과 날짜를 처리하는 메서드와 생성자를 제공하고 Serialized, Comparable Cloneable 인터페이스는 java.util.Date 클래스에 의해 구현되며 java.sql.Date, java.sql.Time 및 java.sql.Timestamp 인터페이스는 java.util.Date 클래스의 기본 클래스입니다.

java.util.Date 생성자

java.util.Date 클래스의 생성자는 다음과 같습니다.

무료 소프트웨어 개발 과정 시작

웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등

1. Date(): Date() 생성자를 사용하여 현재 시간과 날짜를 나타내는 날짜 개체가 생성됩니다.

2. Date(long milliseconds): Date(long milliseconds) 생성자를 사용하여 1970년 1월 1일 st 00:00:00 GMT 이후 지정된 밀리초 동안 날짜 객체가 생성됩니다. .

java.util.Date의 메소드

java.util.Date 클래스의 메소드는 다음과 같습니다.

1. booleanafter(Date date): Boolean after(Date date) 메소드는 현재 날짜가 파라미터로 지정된 날짜 이후인지 확인하는 데 사용됩니다.

2. booleanbefore(Date date): Boolean before(Date date) 메소드는 현재 날짜가 q파라미터로 지정한 날짜보다 이전인지 확인하는 데 사용됩니다.

다음은 java.util.Date의 예입니다.

코드:

import java.util.Date;
public class Example
{
public static void main(String[] args)
{
// a variable called dat1 is defined to store one date
Date dat1=new Date(2020,6,01);
//a variable called dat2 is defined to store another date
Date dat2=new Date(2021,6,01);
//boolean after(Date date) method is used to check if dat1 comes after dat2 date
System.out.println("The date represented by the variable dat1 is after the date represented by the variable dat2 : "+dat1.after(dat2));
//boolean before(Date date) method is used to check if dat1 comes before dat2 date
System.out.println("The date represented by the variable dat1 is before the date represented by the variable dat2 : "+dat1.before(dat2));
}
}
로그인 후 복사

출력:

java.util.날짜

설명: 위 프로그램에서는 dat1이라는 변수가 하나의 날짜를 저장하도록 정의되어 있습니다. 그런 다음 다른 날짜를 저장하기 위해 dat2라는 변수가 정의됩니다. 그런 다음 boolean after(Date date) 메소드를 사용하여 dat1이 dat2 날짜 이후에 오는지 확인하고 반환된 출력이 true 또는 false인지 확인합니다. 그런 다음 boolean before(Date date) 메소드를 사용하여 dat1이 dat2 날짜보다 앞에 왔는지 확인하고 반환된 출력이 true 또는 false인지 확인합니다.

3. Object clone(): 현재 날짜의 복제 객체를 반환하기 위해 object clone() 메소드를 사용합니다.

다음은 java.util.Date의 예입니다.

코드:

import java.util.Date;
public class Main
{
public static void main(String[] args)
{
//an instance of the date class is created
Date dat=new Date(2020,6,01);
//clone method is called on the instance of the date class to create a clone of the given date
System.out.println("The clone of the given date is : "+dat.clone());
}
}
로그인 후 복사

출력:

java.util.날짜

설명: 위 프로그램에서는 날짜 클래스의 인스턴스가 생성됩니다. 그런 다음 날짜 클래스 인스턴스에서 clone 메소드가 호출되어 지정된 날짜의 복제본을 생성합니다.

4. intcompareTo(Date date): int CompareTo(Date date) 메소드는 현재 날짜와 매개변수로 지정된 날짜를 비교하는 데 사용됩니다. 현재 날짜가 매개변수로 지정된 날짜와 동일한 경우 출력은 0으로 반환됩니다. 현재 날짜가 매개변수로 지정된 날짜 이전인 경우 출력은 0보다 작은 값으로 반환됩니다. 현재 날짜가 매개변수로 지정된 날짜 이후인 경우 0보다 큰 출력이 반환됩니다.

5. booleanequals(Date date): boolean equals(Date date) 메소드는 현재 날짜와 동등 매개변수로 지정된 날짜를 비교하는 데 사용됩니다. 현재 날짜가 매개변수로 지정된 날짜와 동일하면 출력이 true로 반환되고, 그렇지 않으면 출력이 false로 반환됩니다.

다음은 java.util.Date의 예입니다.

코드:

import java.util.Date;
public class Example
{
public static void main(String[] args)
{
//an instance of the date class is created to store one date
Date dat1=new Date(2020,6,01);
//an instance of the date class is created to store another date
Date dat2=new Date(2021,6,01);
//compareTo method is used to compare the two dates stored using the two variables defined before
int comp=dat1.compareTo(dat2);
//the result is displayed after comparing the two dates
System.out.println("The result after comparing the two values is : "+comp);
//Equals() method of date class is used to check if the two dates specified are equal
System.out.println("The dates stored in the two variables are equal : "+dat1.equals(dat2));
}
}
로그인 후 복사

출력:

java.util.날짜

설명: 위 프로그램에서는 하나의 날짜를 저장하기 위해 날짜 클래스의 인스턴스가 생성됩니다. 그런 다음 다른 날짜를 저장하기 위해 날짜 클래스의 인스턴스가 생성됩니다. 그런 다음 CompareTo 메서드를 사용하여 이전에 정의된 두 변수를 사용하여 저장된 두 날짜를 비교합니다. 그런 다음 두 날짜를 비교한 후 결과가 표시됩니다. 그런 다음 이전에 정의한 두 변수를 사용하여 저장된 두 날짜가 동일한지 확인하기 위해 equals 메소드를 사용합니다.

6. static Date from(Instant instant): static Date from(Instant instant) 메소드는 인스턴트 날짜로부터 날짜 객체의 인스턴스를 반환하는 데 사용됩니다.

7. long getTime(): long getTime() 메소드는 날짜 객체가 나타내는 시간을 반환하는 데 사용됩니다.

8. inthashCode(): int hashCode() 메서드는 날짜 객체가 나타내는 해시 코드 값을 반환하는 데 사용됩니다.

9. Instant toInstant(): Instant toInstant() 메소드는 현재 날짜를 인스턴트 객체로 변환하는 데 사용됩니다.

10. String toString(): 문자열 toString() 메소드는 주어진 날짜를 인스턴트 개체로 변환하는 데 사용됩니다.

다음은 java.util.Date의 예입니다.

코드:

import java.time.Instant;
import java.util.Date;
public class Example
{
public static void main(String[] args)
{
//an instance of the date class is created which stores the present date
Date dat=new Date();
//instant date and time is obtained using instant.now() method
Instant inst= Instant.now();
//the instant date and time is displayed by using from() method
System.out.println("The instant date is  : "+dat.from(inst));
//getTime() method is used to obtain the number of milliseconds since January 1st 1970
System.out.println("The number of milliseconds since January 1, 1970, 00:00:00 GTM : "+dat.getTime());
//hashcode() method is used to obtain the hash code of the given date
System.out.println("The hash code for the given date is : "+dat.hashCode());
//toInstant() method is called to convert the present date to the instant object
System.out.println("The instant object after converting the present date : "+dat.toInstant());
//toString() method is used to convert the date to string
System.out.println("The date after conversion to string is : "+dat.toString());
}
}
로그인 후 복사

출력:

java.util.날짜

Explanations: In the above program, an instance of the date class is created to store the present date. Then instant date and time are obtained using instant.now() method. Then the instant date and time are displayed by using from the () method. Then getTime() method is used to obtain the number of milliseconds since January 1st, 1970. Then hashcode() method is used to obtain the hash code of the given date. Then toInstant() method is called to convert the present date to the instant object. Then toString() method is used to convert the date to string.

11. void setTime(long time): void setTime(long time) method is used to set the present date and time to the time specified as a parameter.

Below are the examples of java.util.Date:

Code:

import java.util.Date;
public class Example
{
public static void main(String[] args)
{
//an instance of the date class is created to store one date
Date dat=new Date(2020,6,01);
long lil=2000;
//settime() method is used to set the time to the given time specified
dat.setTime(lil);
System.out.println("The time after setting the time to given time is : "+dat.toString());
}
}
로그인 후 복사

Output:

java.util.날짜

Explanations: In the above program, an instance of the date class is created to store one date. Then setTime() method id used to set the present time to the given date.

Conclusion

In this tutorial, we understand the concept of java.util.Date in Java through definition, its constructors and methods through programming examples and their outputs.

위 내용은 java.util.날짜의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

<gum> : Bubble Gum Simulator Infinity- 로얄 키를 얻고 사용하는 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
Nordhold : Fusion System, 설명
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora : 마녀 트리의 속삭임 - Grappling Hook 잠금 해제 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

PHP vs. Python : 차이점 이해 PHP vs. Python : 차이점 이해 Apr 11, 2025 am 12:15 AM

PHP와 Python은 각각 고유 한 장점이 있으며 선택은 프로젝트 요구 사항을 기반으로해야합니다. 1.PHP는 간단한 구문과 높은 실행 효율로 웹 개발에 적합합니다. 2. Python은 간결한 구문 및 풍부한 라이브러리를 갖춘 데이터 과학 및 기계 학습에 적합합니다.

PHP : 웹 개발의 핵심 언어 PHP : 웹 개발의 핵심 언어 Apr 13, 2025 am 12:08 AM

PHP는 서버 측에서 널리 사용되는 스크립팅 언어이며 특히 웹 개발에 적합합니다. 1.PHP는 HTML을 포함하고 HTTP 요청 및 응답을 처리 할 수 ​​있으며 다양한 데이터베이스를 지원할 수 있습니다. 2.PHP는 강력한 커뮤니티 지원 및 오픈 소스 리소스를 통해 동적 웹 컨텐츠, 프로세스 양식 데이터, 액세스 데이터베이스 등을 생성하는 데 사용됩니다. 3. PHP는 해석 된 언어이며, 실행 프로세스에는 어휘 분석, 문법 분석, 편집 및 실행이 포함됩니다. 4. PHP는 사용자 등록 시스템과 같은 고급 응용 프로그램을 위해 MySQL과 결합 할 수 있습니다. 5. PHP를 디버깅 할 때 error_reporting () 및 var_dump ()와 같은 함수를 사용할 수 있습니다. 6. 캐싱 메커니즘을 사용하여 PHP 코드를 최적화하고 데이터베이스 쿼리를 최적화하며 내장 기능을 사용하십시오. 7

Java 8 Stream foreach에서 나누거나 돌아 오시겠습니까? Java 8 Stream foreach에서 나누거나 돌아 오시겠습니까? Feb 07, 2025 pm 12:09 PM

Java 8은 스트림 API를 소개하여 데이터 컬렉션을 처리하는 강력하고 표현적인 방법을 제공합니다. 그러나 스트림을 사용할 때 일반적인 질문은 다음과 같은 것입니다. 기존 루프는 조기 중단 또는 반환을 허용하지만 스트림의 Foreach 메소드는이 방법을 직접 지원하지 않습니다. 이 기사는 이유를 설명하고 스트림 처리 시스템에서 조기 종료를 구현하기위한 대체 방법을 탐색합니다. 추가 읽기 : Java Stream API 개선 스트림 foreach를 이해하십시오 Foreach 메소드는 스트림의 각 요소에서 하나의 작업을 수행하는 터미널 작동입니다. 디자인 의도입니다

PHP 대 기타 언어 : 비교 PHP 대 기타 언어 : 비교 Apr 13, 2025 am 12:19 AM

PHP는 특히 빠른 개발 및 동적 컨텐츠를 처리하는 데 웹 개발에 적합하지만 데이터 과학 및 엔터프라이즈 수준의 애플리케이션에는 적합하지 않습니다. Python과 비교할 때 PHP는 웹 개발에 더 많은 장점이 있지만 데이터 과학 분야에서는 Python만큼 좋지 않습니다. Java와 비교할 때 PHP는 엔터프라이즈 레벨 애플리케이션에서 더 나빠지지만 웹 개발에서는 더 유연합니다. JavaScript와 비교할 때 PHP는 백엔드 개발에서 더 간결하지만 프론트 엔드 개발에서는 JavaScript만큼 좋지 않습니다.

PHP vs. Python : 핵심 기능 및 기능 PHP vs. Python : 핵심 기능 및 기능 Apr 13, 2025 am 12:16 AM

PHP와 Python은 각각 고유 한 장점이 있으며 다양한 시나리오에 적합합니다. 1.PHP는 웹 개발에 적합하며 내장 웹 서버 및 풍부한 기능 라이브러리를 제공합니다. 2. Python은 간결한 구문과 강력한 표준 라이브러리가있는 데이터 과학 및 기계 학습에 적합합니다. 선택할 때 프로젝트 요구 사항에 따라 결정해야합니다.

PHP의 영향 : 웹 개발 및 그 이상 PHP의 영향 : 웹 개발 및 그 이상 Apr 18, 2025 am 12:10 AM

phphassignificallyimpactedwebdevelopmentandextendsbeyondit

PHP : 많은 웹 사이트의 기초 PHP : 많은 웹 사이트의 기초 Apr 13, 2025 am 12:07 AM

PHP가 많은 웹 사이트에서 선호되는 기술 스택 인 이유에는 사용 편의성, 강력한 커뮤니티 지원 및 광범위한 사용이 포함됩니다. 1) 배우고 사용하기 쉽고 초보자에게 적합합니다. 2) 거대한 개발자 커뮤니티와 풍부한 자원이 있습니다. 3) WordPress, Drupal 및 기타 플랫폼에서 널리 사용됩니다. 4) 웹 서버와 밀접하게 통합하여 개발 배포를 단순화합니다.

PHP vs. Python : 사용 사례 및 응용 프로그램 PHP vs. Python : 사용 사례 및 응용 프로그램 Apr 17, 2025 am 12:23 AM

PHP는 웹 개발 및 컨텐츠 관리 시스템에 적합하며 Python은 데이터 과학, 기계 학습 및 자동화 스크립트에 적합합니다. 1.PHP는 빠르고 확장 가능한 웹 사이트 및 응용 프로그램을 구축하는 데 잘 작동하며 WordPress와 같은 CMS에서 일반적으로 사용됩니다. 2. Python은 Numpy 및 Tensorflow와 같은 풍부한 라이브러리를 통해 데이터 과학 및 기계 학습 분야에서 뛰어난 공연을했습니다.

See all articles