10장

1. 날짜와 시간

  • Calendar 클래스: 추상 클래스이므로 메서드를 통해서 구현된 클래스의 인스턴스를 얻어야 함

  • Date 클래스: Calendar 클래스가 추가되면서 대부분의 메서드가 'deprecated' 처리

    • deprecated: 더 이상 사용을 권장하지 않는 대상

2. 형식화 클래스

  • 형식화 클래스: 숫자, 날짜, 텍스트 데이터 등을 일정한 형식에 맞게 표현하는 방법을 제공하는 클래스

2.1. DecimalFormat 클래스

Title
Class DecimalFormat

Module

java.base

Package

java.text

inheritance

Class Description

Note

All Implemented Interfaces: Serializable, Cloneable

Type Signature

public class DecimalFormat extends NumberFormat

Block

10진수의 형식을 지정하는 NumberFormat의 구체적인 서브 클래스

Note

Since

1.1

2.2. 특별 패턴

Symbol
Location
Localized
Meaning

0

Number

Yes

Digit

#

Number

Yes

Digit, zero shows as absent

.

Number

Yes

Decimal separator or monetary decimal separator

-

Number

Yes

Minus sign

,

Number

Yes

Grouping separator

E

Number

Yes

Separates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix.

;

Subpattern boundary

Yes

Separates positive and negative subpatterns

%

Prefix or suffix

Yes

Multiply by 100 and show as percentage

\u2030

Prefix or suffix

Yes

Multiply by 1000 and show as per mille value

¤ (\u00A4)

Prefix or suffix

No

Currency sign, replaced by currency symbol.

'

Prefix or suffix

No

Used to quote special characters in a prefix or suffix, for example, "'#'#" formats 123 to "#123". To create a single quote itself, use two in a row: "# o''clock".

2.3. SimpleDateFormat

Title
Class SimpleDateFormat

Module

java.base

Package

java.text

inheritance

Class Description

Note

All Implemented Interfaces: Serializable, Cloneable

Type Signature

public class SimpleDateFormat extends DateFormat

Block

locale에 따라 날짜 서식을 지정하고 구문을 분석하는 DateFormat의 서브 클래스

Note

Since

1.1

2.4. 날짜와 시간 패턴

Letter
Date or Time Component
Presentation
Examples

G

Era designator

Text

AD

y

Year

Year

1996; 96

Y

Week year

Year

2009; 09

M

Month in year (context sensitive)

Month

July; Jul; 07

L

Month in year (standalone form)

Month

July; Jul; 07

w

Week in year

Number

27

W

Week in month

Number

2

D

Day in year

Number

189

d

Day in month

Number

10

F

Day of week in month

Number

2

E

Day name in week

Text

Tuesday; Tue

u

Day number of week (1 = Monday, ..., 7 = Sunday)

Number

1

a

Am/pm marker

Text

PM

H

Hour in day (0-23)

Number

0

k

Hour in day (1-24)

Number

24

K

Hour in am/pm (0-11)

Number

0

h

Hour in am/pm (1-12)

Number

12

m

Minute in hour

Number

30

s

Second in minute

Number

55

S

Millisecond

Number

978

z

Time zone

General time zone

Pacific Standard Time; PST; GMT-08:00

Z

Time zone

RFC 822 time zone

-0800

X

Time zone

ISO 8601 time zone

-08; -0800; -08:00

참고 자료

  • 자바의 정석 - 도우출판

Last updated