자바로 요일을 표시하는 날짜 형식이 있습니까?
나는 다음과 같은 날짜 형식을 알고
"yyyy-mm-dd"
형식 - 어떤 표시 날짜 2011-02-26
"yyyy-MMM-dd"
표시 형식으로 날짜 - 어떤2011-FEB-26
예 :
SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy/MMM/dd ");
요일 등을 표시하는 데 도움이되는 형식을 원합니다 2011-02-MON
. 요일을 월과 연도의 문자로 표시하고 싶습니다. 이런 형식을 말해 줄 수 있습니까?
'Tue'가 표시되어야합니다.
new SimpleDateFormat("EEE").format(new Date());
'화요일'이 표시되어야합니다.
new SimpleDateFormat("EEEE").format(new Date());
'T'가 표시되어야합니다.
new SimpleDateFormat("EEEEE").format(new Date());
구체적인 예는 다음과 같습니다.
new SimpleDateFormat("yyyy-MM-EEE").format(new Date());
-- 'E'는 트릭을 수행
http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-E");
System.out.println(df.format(date));
SimpleDateFormat sdf=new SimpleDateFormat("EEE");
EEE는 요일을 나타내며 목요일은 목요일로 표시됩니다.
"E"사용
날짜 및 시간 패턴 섹션을 참조하십시오 .
tl; dr
LocalDate.of( 2018 , Month.JANUARY , 23 )
.format( DateTimeFormatter.ofPattern( “uuuu-MM-EEE” , Locale.US ) )
java.time
현대적인 접근법은 java.time 클래스를 사용합니다.
LocalDate ld = LocalDate.of( 2018 , Month.JANUARY , 23 ) ;
요일 이름을 번역하는 데 사용되는 인간 언어를 결정 하는 Locale
등의 방법을 지정합니다 Locale.CANADA_FRENCH
.
DateTimeFormatter f = DateTimeFormatter.ofPattern( “uuuu-MM-EEE” , Locale.US ) ;
String output = ld.format( f ) ;
ISO 8601
그건 그렇고, 당신은 표준 ISO 8601 주 번호 체계에 관심이있을 수 있습니다 : yyyy-Www-d
.
2018-W01-2
1 주차에는 역년의 첫 번째 목요일이 있습니다. 주 월요일에 시작됩니다. 1 년은 52 주 또는 53 주입니다. 역년의 마지막 / 처음 며칠은 다음 / 이전 주 기반 연도에 착륙 할 수 있습니다.
마지막 한 자리 숫자는 월요일-일요일의 1-7입니다.
추가 ThreeTen-추가 을위한 프로젝트에 라이브러리 클래스를 YearWeek
클래스입니다.
java.time에 대하여
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8, Java SE 9, and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and Java SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- Later versions of Android bundle implementations of the java.time classes.
- For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.
I know the question is about getting the day of week as string (e.g. the short name), but for anybody who is looking for the numeric day of week (as I was), you can use the new "u" format string, supported since Java 7. For example:
new SimpleDateFormat("u").format(new Date());
returns today's day-of-week index, namely: 1 = Monday, 2 = Tuesday, ..., 7 = Sunday.
'development' 카테고리의 다른 글
Rails 테스트 스위트에서 단일 테스트를 실행하는 방법은 무엇입니까? (0) | 2020.07.23 |
---|---|
Base64 문자열에 대한 Android 비트 맵 (0) | 2020.07.23 |
SQL 쿼리를 사용하여 테이블 이름을 변경하는 방법은 무엇입니까? (0) | 2020.07.23 |
Mac OS X 10.13 High Sierra에서 homebrew에 대해 / usr / local을 숨길 수 없음 (0) | 2020.07.23 |
rvm을 사용하여 루비 1.9.2-p0을 최신 패치 레벨로 업그레이드하려면 어떻게합니까? (0) | 2020.07.23 |