> Java > java지도 시간 > 본문

자바 DayOfWeek

王林
풀어 주다: 2024-08-30 15:52:29
원래의
702명이 탐색했습니다.

Java DayOfWeek 클래스는 DayOfWeekenums 및 API를 포함하는 패키지로 구성되어 있으며, 이는 논리 요구 사항 또는 코드 구현에 따라 특정 날짜 또는 시간을 가져오는 것과 관련된 다양한 시간대 및 다양한 규칙을 지원합니다. 이 클래스는 구현 로직의 일부로 필요한 프로그래머에게 정확한 타이밍 관련 문제를 제공하거나 상태를 검색하는 데 유용한 데이터를 제공할 수 있는 다양한 필드, 값, 단위, 날짜 및 시간 달력을 사용하여 다른 날짜 및 시간에 액세스하는 데 유용합니다. 시스템입니다.

구문:

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

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

public class <class_name><method_name><arguments>
public DayOfWeek Temporal adjustInto (Temporal temporal)
로그인 후 복사

Java의 DayOfWeek 메서드

Java DayOfWeek에는 다음과 같은 다양한 메서드가 포함되어 있습니다.

1. 시간적

구문:

public Temporal adjustInto(Temporal temporal)
로그인 후 복사

이 방법은 이번 주의 특정 요일을 갖도록 특정 시간 개체를 조정하는 데 사용됩니다. 주어진 입력과 동일한 동작을 갖는 객체를 반환하며, 이는 런타임에 주어진 값과 동일합니다.

예: 시간적 수업의 조정 방법을 시연하기 위해 사용되는 프로그램입니다.

코드:

import java.util.*;
import java.time.*;
public class Adjust_Into {
public static void main(String[] args) {
ZonedDateTimedt = ZonedDateTime.now();
System.out.println(dt);
LocalDate dt2 = LocalDate.parse("2020-05-01");
dt = (ZonedDateTime)dt2.adjustInto(dt);
System.out.println(dt);
}
}
로그인 후 복사

출력:

자바 DayOfWeek

2. 고정 요일

구문:

public static DayOfWeekfrom(TemporalAccessor temporal)
로그인 후 복사

이 메소드는 TemporalAccessor로 인수를 전달하는 DayOfWeek 클래스와 관련된 인스턴스 또는 객체를 얻는 데 사용됩니다.

예: 이 프로그램은 DayOfWeekfrom() 메소드를 정적 메소드의 일부로 시연하는 데 사용됩니다.

코드:

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
public class D_Of_Wk {
public static void main(String[] args) {
LocalDatelcldt = LocalDate.of(2000, Month.APRIL, 23);
DayOfWeekdofwk = DayOfWeek.from(lcldt);
System.out.println("Current_day_of_the_week " + lcldt + " ->> " + dofwk.name());
}
}
로그인 후 복사

출력:

자바 DayOfWeek

3. 정수

구문:

public intget(TemporalField field)
로그인 후 복사

이 메소드는 요일로부터 필드의 지정된 값을 가져오는 데 사용되며, 이는 정수 값으로 인수로 전달될 때 int 값입니다. 해당 필드에서 값을 얻지 못하거나 값이 범위를 벗어나는 경우 해당 필드에서 DateTimeException이 발생합니다.

예: 이 프로그램은 public int get(TemporalField 필드) 방법을 보여줍니다.

코드:

import java.time.LocalDate;
import java.time.temporal.ChronoField;
public class Date_Get {
public static void main(String[] args) {
LocalDate dt2 = LocalDate.parse("2020-06-18");
System.out.println(dt2.get(ChronoField.MONTH_OF_YEAR));
}
}
로그인 후 복사

출력:

자바 DayOfWeek

4. 문자열

구문:

public String getDisplayName(TextStyle style,Locale locale)
로그인 후 복사

이름에서 알 수 있듯이 이 메소드는 주로 '월' 또는 '금요일'과 같은 표시 또는 텍스트 표현에 사용되며 식별에 사용되는 텍스트 이름을 반환하며 기본적으로 편리한 표현을 위해 프로그래머의 입력으로 제공됩니다. 원하는대로 텍스트 표현을 얻으려면. 로케일이나 텍스트 표현이 수행되지 않은 경우 숫자 값을 반환할 가능성이 높습니다.

예: 이 프로그램은 문자열 getDisplayName(TextStyle 스타일, 로케일 로케일)을 보여줍니다.

코드:

import java.time.Month;
import java.time.format.TextStyle;
import java.util.Locale;
public class Mnth_en {
public static void main(String[] args) {
Month mnth = Month.of(5);
System.out.println(mnth.getDisplayName(TextStyle.SHORT, Locale.ENGLISH));
}
}
로그인 후 복사

출력:

자바 DayOfWeek

5. 길다

구문:

public long getLong(TemporalField field)
로그인 후 복사

요일의 길이만큼 매개변수를 전달한 후 값을 가져오는 방법입니다. 지정된 값으로 값을 쿼리하여 지원되지 않는 경우 값을 반환한 다음 반환하고 예외를 발생시킵니다.

예: 이 프로그램은 공개 long getLong(TemporalField 필드)을 보여줍니다.

코드:

import java.time.LocalTime;
import java.time.temporal.ChronoField;
public class Gt_Dt_Time_Ex {
public static void main(String[] args) {
LocalTimetm =LocalTime.parse("12:28:39.20");
long scnd_vl = tm.getLong(ChronoField.MILLI_OF_SECOND);
System.out.println("Mli_Sec_Field: " + scnd_vl);
}
}
로그인 후 복사

출력:

자바 DayOfWeek

6. 부울

구문:

public booleanisSupported(TemporalField field)
로그인 후 복사

필드가 지원되는지 확인하고 지원되지 않는 경우 null 값을 반환합니다. true 또는 false의 부울 값을 지원하고 확인합니다.

예: 이 프로그램은 공개 부울 지원(TemporalField 필드)을 보여줍니다.

코드:

import java.time.YearMonth;
import java.time.temporal.ChronoField;
public class Dt_It_pl {
public static void main(String[] args) {
YearMonthtdYrMn = YearMonth.of(2020, 8);
System.out.println("YearMonth :" + tdYrMn);
booleanvl = tdYrMn.isSupported(ChronoField.EPOCH_DAY);
System.out.println("EPOCH_DAY is considered as one of the fields of YearMonthClass. " + vl);
}
}
로그인 후 복사

출력

자바 DayOfWeek

7. 요일

구문:

public DayOfWeekminus(long days)
로그인 후 복사

이 메소드는 실제 날짜 이전에 지정된 요일을 반환한 다음 DayOfWeek 실제 날짜 일정에 있는 일수를 반환합니다.

예: 이 프로그램은 공개 DayOfWeek 마이너스(장일)를 보여줍니다.

코드:

import java.time.DayOfWeek;
public class Day_of_wk_Minus {
public static void main(String[] args) {
DayOfWeekdy_Of_wk = DayOfWeek.of(4);
System.out.println("Day_Week : "+ dy_Of_wk.name() + " - "+ dy_Of_wk.getValue());
long av = 10;
dy_Of_wk = dy_Of_wk.minus(av);
System.out.println("Day_Week_Earlier "
+ av + " sm_days: "
+ dy_Of_wk.name() + " - "
+ dy_Of_wk.getValue());
}
}
로그인 후 복사

출력

자바 DayOfWeek

8. 고정 요일

구문:

public static DayOfWeekof(intdayOfWeek)
로그인 후 복사
로그인 후 복사
로그인 후 복사

It is used to display the 7 days of the week for an enum representation and then is used to obtain an instance of DayOfWeek from an int value.

Example: This program demonstrates the public static DayOfWeek of(intdayOfWeek).

Code:

import java.time.DayOfWeek;
public class Dy_Of_Wk_Ex {
public static void main(String[] args) {
DayOfWeekdyOfWk = DayOfWeek.of(7);
System.out.println("Day-Of_the_Week - "+ dyOfWk.name());
System.out.println("Int Value of " + dyOfWk.name() + " - " + dyOfWk.getValue());
}
}
로그인 후 복사

Output:

자바 DayOfWeek

9. DayOfWeek

Syntax:

public DayOfWeekplus(long days)
로그인 후 복사

In this method, the calculation structure revolves around getting the days and the values specified by a number of days after the specified value.

Example: This program demonstrates the public DayOfWeek plus(long days).

Code:

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
public class Dy_Of_Wk_Pls {
public static void main(String[] args) {
LocalDatelcldt = LocalDate.of(2020, Month.JANUARY, 22);
DayOfWeekdyOfWk = DayOfWeek.from(lcldt);
System.out.println(dyOfWk.getValue());
dyOfWk = dyOfWk.plus(3);
System.out.println(dyOfWk.getValue());
}
}
로그인 후 복사

Output:

자바 DayOfWeek

10. R

Syntax:

public <R> R query(TemporalQuery<R> query)
로그인 후 복사

The specified strategy object is used for querying a query using the specific query for the queried object, and it can also return a null value throws an exception in case of an undefined or not proper query.

Example: This program demonstrates the public <R> R query(TemporalQuery<R> query).

Code:

import java.time.LocalDate;
import java.time.temporal.TemporalQueries;
public class Locl_Test_Av {
public static void main(String[] args) {
LocalDate dt1 = LocalDate.parse("2020-12-04");
System.out.printf("Value of Locl_date", dt1.query(TemporalQueries.precision()));
}
}
로그인 후 복사

Output:

자바 DayOfWeek

11. ValueRange

Syntax:

public ValueRangerange(TemporalField field)
로그인 후 복사

This ValueRange method gets the range of some valid values for the specified field, which consists of range objects, and then the range of valid value is not null that also needs to keep a check on.

Example: This program demonstrates the public ValueRange range(TemporalField field).

Code:

import java.time.LocalTime;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
public class GField_For_Umk {
public static void main(String[] args) {
LocalTime lk_1 = LocalTime.parse("10:22:06");
ValueRange result = lk_1.range(ChronoField.CLOCK_HOUR_OF_AMPM);
System.out.println("CLOCK_HOUR_OF_AMPM: " + result);
}
}
로그인 후 복사

Output:

자바 DayOfWeek

12. static DayOfWeek

Syntax:

public static DayOfWeekof(intdayOfWeek)
로그인 후 복사
로그인 후 복사
로그인 후 복사

This method returns specific enum type constants with specified names used for matching the identifiers with the declared enums and values as designated to the method.

Example: This program demonstrates the public static DayOfWeek of(intdayOfWeek).

Code:

import java.time.DayOfWeek;
public class Dy_Of_Week_Ging {
public static void main(String[] args) {
DayOfWeekdy_Of_wk = DayOfWeek.of(4);
System.out.println("Dy_Of_the_week -" + dy_Of_wk.name());
System.out.println("int_val_of" + dy_Of_wk.name() + " - " + dy_Of_wk.getValue());
}
}
로그인 후 복사

Output:

자바 DayOfWeek

13. static DayOfWeek[]

Syntax:

public static DayOfWeekof(intdayOfWeek)
로그인 후 복사
로그인 후 복사
로그인 후 복사

This method is specifically used to obtain an instance which is the DayOfWeek instance, from an int value and returns a singleton day-of-week which is not null. It throws an exception if the day-week-of is invalid.

Example: This program demonstrates the public static DayOfWeek of(intdayOfWeek)

Code:

import java.time.DayOfWeek;
public class Dy_Of_Week_Int {
public static void main(String[] args) {
DayOfWeekdy_Of_wk = DayOfWeek.of(6);
System.out.println("Day_Of_The_Wk - "+ dy_Of_wk.name());
System.out.println("Int_Vl_Of " + dy_Of_wk.name() + " - "+ dy_Of_wk.getValue());
}
}
로그인 후 복사

Output:

자바 DayOfWeek

Conclusion

This class is very useful in terms of programming where there are huge requirements and something related to the time-bound components or determine which timing constraints are needed for the implementation, which indicates any system or project with timings. Date of the week or month any module is fully associated with Java and DayOfWeek.

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

관련 라벨:
원천:php
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!