자바 기간
자바의 Duration은 시간을 초와 나노초 단위로 측정하는 데 사용되는 클래스입니다. Java의 기간 클래스 패키지는 java.time.Duration입니다. Duration 클래스 객체는 기간을 지정하거나 두 시간 간의 차이를 결정하는 데 사용됩니다. Duration 객체는 불변이고 스레드로부터 안전합니다. Duration 객체는 불변이므로 일단 생성되면 해당 값을 변경할 수 없습니다. 그러나 다른 Duration 개체를 기반으로 새 Duration 개체를 만들 수 있습니다. Duration 클래스는 객체 클래스(객체는 Java의 모든 클래스의 슈퍼클래스이므로)를 상속하고 Comparable 인터페이스를 구현합니다.
무료 소프트웨어 개발 과정 시작
웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등
구문
Java의 Duration 클래스 선언 구문은 다음과 같습니다.
public final class Duration extends Object implements Comparable < Duration >, TemporalAmount, Serializable { // variables and method of the class Duration}
기간 목록
아래에는 Duration 클래스 메소드 목록이 예제 코드와 함께 설명되어 있습니다. 유사한 메서드에 대해 예제 코드를 추가로 사용할 수 있습니다(각 메서드 예제 코드는 제공되지 않음):
- 기간 abs(): 이 메소드는 양수 길이의 기간 복사본을 반환합니다.
- long get(TemporalUnit 단위): 요청한 단위의 값을 반환합니다.
- 정적 기간 사이(Temporal startInclusive, Temporal endExclusive): 두 시간 개체 사이의 기간인 기간 개체를 반환합니다.
예시 #1
아래의 샘플 자바 코드를 통해 위의 메소드를 이해했습니다.
코드:
package p1; import java.time.Duration; import java.time.LocalTime; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.between(LocalTime.MAX,LocalTime.MIN); System.out.println(d.get(ChronoUnit.SECONDS)); Duration absd = d.abs(); System.out.println(absd.get(ChronoUnit.SECONDS)); } }
출력:
- Temporal addTo(Temporal temporary): 시간 객체와 이 기간 객체를 더한 기간 객체를 반환합니다.
- Duration Divider(long divisor): 이 기간을 제수로 나눈 기간 객체를 반환합니다.
예시 #2
아래 샘플 자바 코드를 통해 위의 메소드를 이해합니다.
코드:
package p1; import java.time.Duration; import java.time.*; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.between(LocalTime.MAX,LocalTime.MIN); LocalDateTime date = LocalDateTime.now(); System.out.println(date); date = (LocalDateTime)d.addTo(date); System.out.println(date); Duration d1 = d.dividedBy(4); System.out.println(d1); System.out.println(d.getSeconds()); System.out.println(d1.getSeconds()); } }
출력:
- int CompareTo(Duration otherDuration): 이 기간과 지정된 기간을 비교합니다.
- boolean equals(Object otherDuration): 지정된 Duration으로 이 기간을 확인하고 Boolean을 반환합니다.
- boolean isNegative(): 이 기간이 음수이면 True를 반환합니다.
- boolean isZero(): 이 기간 길이가 0이면 True를 반환합니다.
예시 #3
아래 샘플 자바 코드를 통해 위의 메소드를 이해합니다.
코드:
package p1; import java.time.Duration; import java.time.*; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.between(LocalTime.NOON,LocalTime.MAX); Duration d1 = Duration.between(LocalTime.NOON,LocalTime.MIN); System.out.println(d1.getSeconds()); System.out.println(d.compareTo(d1)); System.out.println(d1.compareTo(d1)); System.out.println(d1.compareTo(d)); System.out.println(d1.equals(d)); System.out.println(d1.isNegative()); System.out.println(d1.isZero()); } }
출력:
- 정적 지속 시간(TemporalAmount amount): 시간적 양에서 지속 시간의 인스턴스를 얻습니다.
예시 #4
아래 샘플 자바 코드를 통해 위의 방법을 이해합니다.
코드:
package p1; import java.time.Duration; import java.time.*; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.from(ChronoUnit.DAYS.getDuration()); System.out.println(d.toMinutes()); } }
출력:
- int getNano(): 나노초 단위로 기간을 반환합니다.
- long getSeconds(): 기간을 초 단위로 반환합니다.
- 목록<임시단위> getUnits(): 이 기간에 지원되는 단위 집합을 반환합니다.
- int hashCode(): 이 기간 동안 해시 코드를 반환합니다.
예시 #5
아래 샘플 자바 코드를 통해 위의 방법을 이해합니다.
코드:
package p1; import java.time.Duration; import java.time.*; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.between(LocalTime.NOON,LocalTime.MAX); System.out.println(d.getUnits()); System.out.println(d.toMinutes()); System.out.println(d.getSeconds()); System.out.println(d.getNano()); System.out.println(d.getClass()); } }
출력:
- Duration minus(Duration duration):- Returns object which results from this duration subtracted with the specified duration.
- Duration minus(long amountToSubtract, TemporalUnit unit): Returns object resulting from this duration subtracted with the specified duration.
- Duration minusDays(long daysToSubtract): Returns object which results from this duration subtracted with the specified duration in standard 24-hour days.
- Duration minusHours(long hoursToSubtract): Returns object resulting from this duration subtracted with the specified duration in hours.
- Duration minusMillis(long millisToSubtract): Returns object resulting from this duration subtracted with the specified duration in milliseconds.
- Duration minusMinutes(long minutesToSubtract): Returns object resulting from this duration subtracted with the specified duration in minutes.
- Duration minusNanos(long nanosToSubtract): Returns object resulting from this duration subtracted with the specified duration in nanoseconds.
- Duration minusSeconds(long secondsToSubtract): Returns object resulting from this duration subtracted with the specified duration in seconds.
- Duration multipliedBy(long multiplicand): Returns object resulting from this duration multiplied by the scalar.
- Duration negated() – Returns object which results from this duration with the length negated.
- static duration of(long amount, TemporalUnit unit): Returns Duration object representing an amount in the specified unit.
- static Duration ofDays(long days): Returns Duration object of standard 24-hour days.
- static Duration ofHours(long hours): Returns Duration object of the hour.
- static Duration ofMillis(long millis): Returns Duration object of milliseconds.
- static Duration ofMinutes(long minutes): Returns Duration object of minutes.
- static Duration ofNanos(long nanos): Returns Duration object of nanoseconds.
- static Duration ofSeconds(long seconds): Returns Duration object of seconds.
- static Duration ofSeconds(long seconds, long nanoAdjustment): Returns Duration object of seconds and nanoseconds adjustment.
Example #6
We understand the above methods with the below sample java code:
Code:
package p1; import java.time.Duration; import java.time.*; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.ofDays(6); System.out.println(d.getSeconds()); Duration d1 = d.minusDays(3); System.out.println(d1.getSeconds()); d = Duration.ofHours(6); System.out.println(d.getSeconds()); d1 = d.minusHours(2); System.out.println(d1.getSeconds()); } }
Output:
- static Duration parse(CharSequence text): Return duration object from a text, for example, PnDTnHnMn.nS.
- Duration plus(Duration duration): Return the duration object of this duration with added the specified duration.
- Duration plus(long amountToAdd, TemporalUnit unit): Return the duration object of this duration with add the specified duration.
- Duration plusDays(long daysToAdd): Return the duration object of this duration with add the specified duration in 24-hour days.
- Duration plusHours(long hoursToAdd): Return the duration object of this duration with add the specified duration in hours.
- Duration plusMillis(long millisToAdd): Return the duration object of this duration with add the specified duration in milliseconds.
- Duration plusMinutes(long minutesToAdd): Return the duration object of this duration with the add specified duration in minutes.
- Duration plusNanos(long nanosToAdd): Return the duration object of this duration with add the specified duration in nanoseconds.
- Duration plusSeconds(long secondsToAdd): Return the duration object of this duration with the specified duration in seconds.
Example #7
We understand the above methods with the below sample java code:
Code:
package p1; import java.time.Duration; import java.time.*; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.ofDays(6); System.out.println(d.getSeconds()); Duration d1 = d.plusDays(2); System.out.println(d1.getSeconds()); d = Duration.ofHours(6); System.out.println(d.getSeconds()); d1 = d.plusHours(2); System.out.println(d1.getSeconds()); } }
Output:
- Temporal subtractFrom(Temporal temporal): Return Subtraction of this duration from the temporal object.
- long toDays(): Return the number of days in this duration.
- long toHours(): Return the number of hours in this duration.
- long toMillis(): Return the number of milliseconds in this duration.
- long toMinutes(): return the number of minutes in this duration.
- long toNanos(): return the number of nanoseconds in this duration.
- String toString(): Return this duration in string representation, such as PT8H6M12.345S.
Example #8
We understand the above methods with the below sample java code:
Code:
package p1; import java.time.Duration; import java.time.*; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.ofDays(6); System.out.println(d.toHours()); Duration d1 =Duration.ofHours(24) ; System.out.println(d1.toDays()); } }
Output:
- Duration withNanos(int nanoOfSecond): Returns duration object with the specified nanoofsecond.
- Duration withSeconds(long seconds): Returns duration object of this duration with the seconds of the specified amount.
Example #9
We understand the above methods with the below sample java code:
Code:
package p1; import java.time.Duration; import java.time.*; import java.time.temporal.ChronoUnit; public class DurationClassDemo { public static void main(String[] args) { Duration d = Duration.ofDays(6); System.out.println(d.toString()); d = d.withSeconds(3000); System.out.println(d.toString()); } }
Output:
Conclusion
The Duration class is one of the built-in class in java, which is used to measure time in seconds and nanoseconds and add, subtract, and convert the duration, or, in simple words, the duration class allows performance operation on time or day duration. The duration class is available in java.time.Duration package of java.
위 내용은 자바 기간의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

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

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

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

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

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

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

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

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

뜨거운 주제











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

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

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

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

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

캡슐은 3 차원 기하학적 그림이며, 양쪽 끝에 실린더와 반구로 구성됩니다. 캡슐의 부피는 실린더의 부피와 양쪽 끝에 반구의 부피를 첨가하여 계산할 수 있습니다. 이 튜토리얼은 다른 방법을 사용하여 Java에서 주어진 캡슐의 부피를 계산하는 방법에 대해 논의합니다. 캡슐 볼륨 공식 캡슐 볼륨에 대한 공식은 다음과 같습니다. 캡슐 부피 = 원통형 볼륨 2 반구 볼륨 안에, R : 반구의 반경. H : 실린더의 높이 (반구 제외). 예 1 입력하다 반경 = 5 단위 높이 = 10 단위 산출 볼륨 = 1570.8 입방 단위 설명하다 공식을 사용하여 볼륨 계산 : 부피 = π × r2 × h (4

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

phphassignificallyimpactedwebdevelopmentandextendsbeyondit
