Bibi's DevLog ๐Ÿค“๐ŸŽ

[Java] ๋‹ฌ๋ ฅ ๋งŒ๋“ค๊ธฐ - ํ˜„์žฌ ๋‚ ์งœ ๋ฐ ํŠน์ • ๋‚ ์งœ ๋‹ฌ๋ ฅ ์ถœ๋ ฅ. (Calendar, Date, SimpleDateFormat, ์œค๋…„) ๋ณธ๋ฌธ

๐Ÿ–ฅ BE ๋ฐฑ์—”๋“œ/Java ์ž๋ฐ”

[Java] ๋‹ฌ๋ ฅ ๋งŒ๋“ค๊ธฐ - ํ˜„์žฌ ๋‚ ์งœ ๋ฐ ํŠน์ • ๋‚ ์งœ ๋‹ฌ๋ ฅ ์ถœ๋ ฅ. (Calendar, Date, SimpleDateFormat, ์œค๋…„)

๋น„๋น„ bibi 2020. 11. 18. 19:11

์ž๋ฐ”๋กœ ๋‹ฌ๋ ฅ์„ ๋งŒ๋“ค๊ณ  ์ถœ๋ ฅํ•˜๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

์ถœ๋ ฅํ˜•ํƒœ

๊ณผ๊ฑฐ ๋‹ฌ๋ ฅ (2020๋…„ 2์›”)
ํ˜„์žฌ ๋‹ฌ๋ ฅ (2020๋…„ 11์›”)


ํด๋ž˜์Šค : MyCalendar

(ํด๋ž˜์Šค๋ช…์„ Calendar๋กœ ํ–ˆ๋”๋‹ˆ Calendarํด๋ž˜์Šค๋ฅผ ์ž„ํฌํŠธํ•  ๋•Œ ์—๋Ÿฌ๊ฐ€ ๋‚˜์„œ ๋ฐ”๊ฟจ๋‹ค)

starter()

  • ๋‹ฌ๋ ฅ์„ ์‹คํ–‰ํ•˜๋Š” ๋ฉ”์„œ๋“œ
    • a๋ฅผ ์ž…๋ ฅํ•ด buildCurrendCalendar()๋ฅผ ์‹คํ–‰, ํ˜„์žฌ ๋‹ฌ๋ ฅ์„ ์ถœ๋ ฅ.
    • z๋ฅผ ์ž…๋ ฅํ•ด getYear(),getMonth()๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์ž…๋ ฅ๊ฐ’์„ ๋ฐ›์•„ buildPastCalendar()๋ฅผ ์‹คํ–‰
    • ์ž˜๋ชป ์ž…๋ ฅ์‹œ starter()๋ฅผ ๋ฐ˜๋ณต์‹คํ–‰

getYear(), getMonth()

  • ์—ฐ๋„ / ์›” ์„ ๋ฐ›์•„์˜ค๋Š” ๋ฉ”์„œ๋“œ. ๊ณผ๊ฑฐ ๋‹ฌ๋ ฅ ์ถœ๋ ฅํ•  ๋•Œ๋งŒ ์‹คํ–‰๋จ.
  • ๋‘˜ ๋‹ค ์ž์—ฐ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•˜๋ฉฐ ์›”์€ 1-12์‚ฌ์ด ์ž์—ฐ์ˆ˜๋งŒ ์ž…๋ ฅ ๊ฐ€๋Šฅ.

getCurrent()

  • ํ˜„์žฌ ์—ฐ์›”์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฉ”์„œ๋“œ. ํ˜„์žฌ ๋‹ฌ๋ ฅ ์ถœ๋ ฅํ•  ๋•Œ๋งŒ ์‹คํ–‰๋จ.
  • Calendarํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ํ˜„์žฌ ์—ฐ๋„์™€ ํ˜„์žฌ ์›”์„ ๊ฐ€์ ธ์˜จ๋‹ค
    • โ— Calendarํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ํ˜„์žฌ ์›”์„ ๊ฐ€์ ธ์˜ฌ ๋•Œ๋Š” +1 ์„ ํ•ด ์ค˜์•ผ ํ•œ๋‹ค. 1์›”์€ 0์œผ๋กœ, 12์›”์€ 11๋กœ ์กฐํšŒ๋˜๊ธฐ ๋•Œ๋ฌธ.

isLeapYear(int year)

  • ์œค๋…„์„ ์ฒดํฌํ•˜๋Š” ๋ฉ”์„œ๋“œ. ํ˜„์žฌ ๋‹ฌ๋ ฅ, ๊ณผ๊ฑฐ ๋‹ฌ๋ ฅ ๋ชจ๋‘ ์‹คํ–‰๋จ.
  • ์œค๋…„ = ์—ฐ๋„๊ฐ€ 4์˜ ๋ฐฐ์ˆ˜์ด๋ฉด์„œ, 100์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹ˆ๊ฑฐ๋‚˜ 400์˜ ๋ฐฐ์ˆ˜์ผ ๋•Œ ์œค๋…„์ด๋‹ค.
    • ์ฆ‰ 1. 4์˜ ๋ฐฐ์ˆ˜์ด์ง€๋งŒ 100์˜ ๋ฐฐ์ˆ˜๋Š” ์•„๋‹Œ ์—ฐ๋„, 2. 4์˜ ๋ฐฐ์ˆ˜์ด๋ฉด์„œ 400์˜ ๋ฐฐ์ˆ˜์ธ ์—ฐ๋„ ๊ฐ€ ์œค๋…„์— ํ•ด๋‹นํ•œ๋‹ค.
  • if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)๋กœ ๊ฒ€์‚ฌํ•ด ์œค๋…„์ด๋ฉด true, ์•„๋‹ˆ๋ฉด false ๋ฐ˜ํ™˜.

calMonth1stDayWeek(int year, int month)

  • ์–ด๋–ค ์›”์˜ '1์ผ'์˜ ์š”์ผ์„ ๊ตฌํ•˜๋Š” ๋ฉ”์„œ๋“œ.
  • ๋‚˜๋Š” 1์ผ์˜ ์š”์ผ์„ ๊ตฌํ•˜๊ณ , ๊ทธ ์š”์ผ๋ถ€ํ„ฐ 1~๋งˆ์ง€๋ง‰๋‚  ๊นŒ์ง€ ์ถœ๋ ฅํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋‹ฌ๋ ฅ์„ ๋งŒ๋“ค์—ˆ๊ธฐ ๋•Œ๋ฌธ์— 1์ผ์˜ ์š”์ผ์„ ๊ตฌํ•˜๋Š” ๊ฒƒ์ด ๊ต‰์žฅํžˆ ์ค‘์š”ํ–ˆ๋‹ค. (๊ทธ๋ž˜์„œ ๋ฉ”์„œ๋“œ๋ช…์ด ๋ณต์žกํ•œ ๊ฑด ์•„๋‹ˆ๋‹ค. ํ‘ํ‘..)
    • "์ž๋ฐ” ํŠน์ •๋‚ ์งœ ์š”์ผ ๊ตฌํ•˜๊ธฐ"๋กœ ๊ตฌ๊ธ€๋งํ•˜๋ฉด ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์ด ๋‚˜์˜ค๋Š”๋ฐ ๋  ๋•Œ๊นŒ์ง€ ์ด๊ฒƒ์ €๊ฒƒ ํ•ด ๋ณด์•˜๋‹ค.
    • ๊ตฌ๊ธ€๋งํ•œ ๋งํฌ1, ๋งํฌ2,๋งํฌ3 ๋“ค.. ๋ชจ๋‘ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.๐Ÿ™‡‍โ™€๏ธ
  • ์ž„ํฌํŠธํ–ˆ๋˜ Calendarํด๋ž˜์Šค์™€ Dateํด๋ž˜์Šค๋ฅผ ๊ฐ๊ฐ ๋ถˆ๋Ÿฌ์˜จ๋‹ค
  • YMD = ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์•„์˜จ year์™€ month์™€ "-01"์„ ์ด์–ด๋ถ™์—ฌ "yyyy-MM-01"ํ˜•ํƒœ๋กœ ๋งŒ๋“ ๋‹ค
    • ๊ณผ๊ฑฐ ๋‹ฌ๋ ฅ์€ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ getYear(), getMonth()์˜ ๋ฆฌํ„ด๊ฐ’์ด๋ฉฐ
    • ํ˜„์žฌ ๋‹ฌ๋ ฅ์€ ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ getCurrent()์˜ ๋ฆฌํ„ด๊ฐ’์ด๋‹ค.
  • ํ™•์ธ์„ ์œ„ํ•ด ์˜ค๋Š˜ ๋‚ ์งœ๋ฅผ ํ•œ๋ฒˆ ์ถœ๋ ฅํ•ด ์ค€๋‹ค
  • try-catch๋ฅผ ์“ด ์ด์œ ๋Š” calendar.setTime(formatter.parse(YMD));๋ถ€๋ถ„์—์„œ parse์— ๋Œ€ํ•œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ํ•˜์ง€ ์•Š์œผ๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์™œ ๊ทธ๋Ÿฐ์ง€๋Š” ๋‚˜์ค‘์— ๋” ๊ณต๋ถ€ํ•ด์•ผ๊ฒ ๋‹ค (ParseException)
  • calendar.get(Calendar.DAY_OF_WEEK);์„ ํ†ตํ•ด ๋‚˜์˜จ ๊ฒฐ๊ณผ๊ฐ’์€ 1์ด ์ผ์š”์ผ, 2๊ฐ€ ์›”์š”์ผ .. 7์ด ํ† ์š”์ผ ์ด๋‹ค.

buildCurrentCalendar()

  • ํ˜„์žฌ ๋‚ ์งœ์˜ ๋‹ฌ๋ ฅ์„ ๋งŒ๋“œ๋Š” ๋ฉ”์„œ๋“œ.

    1. ์—ฐ, ์›” ) getCurrent()์—์„œ ๋ฐ›์•„์˜จ๋‹ค
    1. ์›”์˜ ์ตœ๋Œ€์ผ)
    • ์ตœ๋Œ€์ผ์ธ dayMax๋Š” ๊ฐ ์›”์— ๋Œ€ํ•œ ๋งˆ์ง€๋ง‰ ์ผ์ˆ˜๋ฅผ ๋‹ด์•„ ๋†“์€ ๋ฐฐ์—ด์ธ dayData ๋˜๋Š” dayDataLeapYear์—์„œ ๊บผ๋‚ด ์“ด๋‹ค.
    • dayDataLeapYear์€ 2์›”์— ํ•ด๋‹นํ•˜๋Š” ์ผ์ˆ˜๊ฐ€ 29๋กœ ๋˜์–ด ์žˆ๋‹ค.
    • ๊บผ๋‚ด ์“ธ ๋•Œ isLeapYear()์˜ ๊ฒฐ๊ณผ๊ฐ’์ด true์ด๊ณ , 2์›”์ผ ๋•Œ๋งŒ dayDataLeapYear์—์„œ ๊บผ๋‚ด์“ฐ๋„๋ก ํ–ˆ๋‹ค.
    • (๊บผ๋‚ด ์“ธ ๋•Œ๋Š” ์ธ๋ฑ์Šค๊ฐ’์€ ์›”-1์„ ํ•ด์•ผ ํ•œ๋‹ค : 1์›”์€ 0๋ฒˆ์งธ, 2์›”์€ 1๋ฒˆ์งธ.. ์— ๋“ค์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ)
    1. ์›”์˜ 1์ผ์˜ ์š”์ผ ) calMonth1stDayWeek(year,month) ๋กœ ์—ฐ, ์›”์„ ๋ณด๋‚ด ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์•„์˜จ๋‹ค
    1. ์—ฐ, ์›”, ์ตœ๋Œ€์ผ, ์›”์˜ 1์ผ์˜ ์š”์ผ์„ ๊ฐ€์ง€๊ณ  printCalendar() ์—์„œ ์ถœ๋ ฅํ•˜๊ฒŒ ํ•œ๋‹ค.

buildPastCalendar(int year, int month)

  • ๊ณผ๊ฑฐ ๋‚ ์งœ์˜ ๋‹ฌ๋ ฅ์„ ๋งŒ๋“œ๋Š” ๋ฉ”์„œ๋“œ.

    1. ์—ฐ, ์›” ) ๋ถ€๋ถ„์„ ์ œ์™ธํ•˜๊ณ ๋Š” buildCurrendCalendar()์™€ ๋˜‘๊ฐ™๋‹ค.
    • ๊ณผ๊ฑฐ ๋‚ ์งœ์˜ ์—ฐ, ์›”์€ getYear(), getMonth()์—์„œ ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์—ฐ, ์›”์„ ๋ฐ›์•„์˜จ๋‹ค.

printCalendar(int year, int month, int dayMax, int dayWeek1)

  • ์—ฐ, ์›”, ์ตœ๋Œ€์ผ, ์›”์˜ 1์ผ์˜ ์š”์ผ ์„ ๋ฐ›์•„์™€์„œ ์ฝ˜์†”์ฐฝ์— ์ถœ๋ ฅํ•˜๋Š” ๋ฉ”์„œ๋“œ
  • ๋‹ฌ๋ ฅ์„ ์ถœ๋ ฅํ•˜๋Š” ๋ฐ๋„ ์ •๋ง ๋‹ค์–‘ํ•œ ๋ฐฉ์‹์ด ์žˆ์—ˆ๋‹ค..
    • "์ž๋ฐ” ๋‹ฌ๋ ฅ ๋งŒ๋“ค๊ธฐ"๋กœ ๊ตฌ๊ธ€๋งํ•˜๋ฉด ๋‹ค์–‘ํ•œ ๋ฐฉ์‹์ด ๋‚˜์˜จ๋‹ค. ์—ญ์‹œ ์ด๊ฒƒ์ €๊ฒƒ ์ฐธ๊ณ ํ•˜๋ฉฐ ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๋ฐฉ์‹๋Œ€๋กœ ๋งŒ๋“ฆ.
    • ๊ตฌ๊ธ€๋งํ•œ ๋งํฌ1-์‹œ๋ฆฌ์ฆˆ, ๋งํฌ2, ๋งํฌ3 ๋“ค. ๋ชจ๋‘๋ชจ๋‘ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค๐Ÿ™‡‍โ™€๏ธ
  • ๋‹ฌ๋ ฅ ์ถœ๋ ฅ์—๋Š” ๋ฐฐ์—ด/์ด์ฐจ์›๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๊ณผ ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒƒ์œผ๋กœ ํฌ๊ฒŒ ๋‚˜๋‰˜๋Š” ๊ฒƒ ๊ฐ™์•˜๋‹ค. ๋‚˜๋Š” ๋นˆ ๋‚ ์งœ์— ๊ณต๋ฐฑ์„ ์ถ”๊ฐ€ํ•˜๊ณ , ๋ฐ˜๋ณต๋ฌธ์„ ์ข€ ๋” ํŽธํ•˜๊ฒŒ ์“ฐ๊ณ  ์‹ถ์–ด์„œ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋‹ค. (๋ฐฐ์—ด ์‚ฌ์šฉํ•˜๋ ค๋‹ˆ๊นŒ ๋จธ๋ฆฌ๊ฐ€ ๋ณต์žกํ•ด์ ธ์„œ๐Ÿ˜…)
  • ๋‹ฌ๋ ฅ ์ œ๋ชฉ(yyyy๋…„ MM์›”) ๊ณผ ์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ†  ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.
  • ๋‹ฌ๋ ฅ์˜ 1์ผ์˜ ์š”์ผ(dayWeek1) ์•ž๋ถ€๋ถ„์„ ์ฑ„์šธ ๊ณต๋ฐฑ (๋‚˜๋Š” โœจ) ์„ ์ถœ๋ ฅํ–ˆ๋‹ค.
    • dayWeek1 = 1 ์ด๋ฉด ์ผ์š”์ผ๋ถ€ํ„ฐ 1,2,3,4,5.. ๊ฐ€ ์ฑ„์›Œ์ง€๋ฏ€๋กœ ๊ณต๋ฐฑ์€ 0์ด๋‹ค.
    • dayWeek1 = 2 ์ด๋ฉด ์›”์š”์ผ๋ถ€ํ„ฐ 1,2,3,4.. ๊ฐ€ ์ฑ„์›Œ์ง€๋ฏ€๋กœ ๊ณต๋ฐฑ์€ 1์ด๋‹ค.
    • ์ฆ‰ dayWeek1(1์ผ์˜ ์š”์ผ) -1 ๋งŒํผ์˜ ๊ณต๋ฐฑ์ด ํ•„์š”ํ•˜๋‹ค.
  • ๊ณต๋ฐฑ์„ ์ถœ๋ ฅํ•œ ๋‹ค์Œ์—๋Š” ๋‚ ์งœ๋ฅผ 1,2,3,4,5..์ตœ๋Œ€์ผ ๋งŒํผ ์ถœ๋ ฅํ•˜๋˜
    • ์ผ์˜ ์ž๋ฆฌ์ผ ๋•Œ (1~9) ๋Š” ์ˆซ์ž ์•ž์— ๊ณต๋ฐฑ์„ ํ•˜๋‚˜ ๋” ์ถ”๊ฐ€ํ–ˆ๋‹ค.
    • ์ค„๋ฐ”๊ฟˆ : ๊ณต๋ฐฑ(dayWeek1 -1) + ์ž…๋ ฅ๋œ์ˆซ์ž(i) ๊ฐ€ 7์ด๋ฉด ์ผ์›”ํ™”์ˆ˜๋ชฉ๊ธˆํ†  ๊ฐ€ ์ฑ„์›Œ์ง„ ๊ฒƒ์ด๋ฏ€๋กœ ์ค„๋ฐ”๊ฟˆ์„ ํ•ด์•ผ ํ•œ๋‹ค.
    • if ((dayWeek1 - 1 + i ) % 7 == 0) ์ผ ๋•Œ System.out.println();์œผ๋กœ ์ค„๋ฐ”๊ฟˆ์„ ํ–ˆ๋‹ค.

์ €๋Š” ์ดˆ๋ณด์ด๊ธฐ ๋•Œ๋ฌธ์— ์ œ ์ฝ”๋“œ๊ฐ€ ์ข‹์€ ์ฝ”๋“œ๊ฑฐ๋‚˜ ๊น”๋”ํ•œ ์ฝ”๋“œ๋Š” ์•„๋‹ ๊ฒ๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ์ผ๋‹จ ๋™์ž‘์€ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ณต์œ ํ•˜๋Š” ์ฐจ์›์—์„œ ์˜ฌ๋ฆฝ๋‹ˆ๋‹ค. ์ฐธ๊ณ ๋งŒ ํ•˜์„ธ์š”!

์ „์ฒด ์ฝ”๋“œ

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class MyCalendar {
    static MyCalendar myCalendar = new MyCalendar();

    public static void main(String[] args) {
        myCalendar.starter();
    }

    public void starter(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("ํ˜„์žฌ ๋‹ฌ๋ ฅ ์ถœ๋ ฅ : a , ๊ณผ๊ฑฐ ๋‹ฌ๋ ฅ ์ถœ๋ ฅ : z");
        String input = scanner.next();
        switch (input) {
            case "a" :
                buildCurrentCalendar();
                break;
            case "z" :
                int year = getYear();
                int month = getMonth();
                buildPastCalendar(year, month);
                break;
            default:
                System.out.println("์ž˜๋ชป๋œ ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ์ž…๋ ฅํ•˜์„ธ์š”");
                starter();
                break;
        }
    }

    public int getYear() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("\n๐Ÿ‘‰ ์ถœ๋ ฅ์„ ์›ํ•˜๋Š” ์—ฐ๋„๋ฅผ ์ˆซ์ž๋กœ ์ž…๋ ฅํ•˜์„ธ์š”.");
        int yearInput = scanner.nextInt();
        if (yearInput <= 0) {
            System.out.println("โ— ์—ฐ๋„๋Š” ์ž์—ฐ์ˆ˜๋กœ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.");
            yearInput = scanner.nextInt();
        }
        return yearInput;
    }

    public int getMonth() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("\n๐Ÿ‘‰ ์ถœ๋ ฅ์„ ์›ํ•˜๋Š” ์›”์„ ์ˆซ์ž๋กœ ์ž…๋ ฅํ•˜์„ธ์š”.");
        int monthInput = scanner.nextInt();
        if (monthInput <= 0 || monthInput > 12) {
            System.out.println("โ— ์›”์€ 1์ด์ƒ 12์ดํ•˜์˜ ์ž์—ฐ์ˆ˜๋กœ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.");
            monthInput = scanner.nextInt();
        }
        return monthInput;
    }

    public int[] getCurrent() {
        Calendar calendar = Calendar.getInstance();
        int currentYear = calendar.get(Calendar.YEAR);
        int currentMonth = calendar.get(Calendar.MONTH) + 1;
        int[] currentYearMonth = {currentYear, currentMonth};
        return currentYearMonth;
    }

    public boolean isLeapYear(int year) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
            return true;
        else
            return false;
    }

    public int calMonth1stDayWeek(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        Date currentTime = new Date();
        String YMD = year + "-" + month + "-01";
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String today = formatter.format(currentTime);
        System.out.println("<์˜ค๋Š˜ ๋‚ ์งœ๋Š” " + today + "์ž…๋‹ˆ๋‹ค>");
        try {
            calendar.setTime(formatter.parse(YMD));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int dayNum = calendar.get(Calendar.DAY_OF_WEEK);
        // 1(์ผ) 2(์›”) 3(ํ™”) 4(์ˆ˜) 5(๋ชฉ) 6(๊ธˆ) 7(ํ† )
        return dayNum;
    }

    public void buildCurrentCalendar() {
        //(๊ธฐ๋ณธ๊ฐ’์œผ๋กœ๋Š” ํ˜„์žฌ๋‚ ์งœ์˜ ๋‹ฌ๋ ฅ์„ ์ถœ๋ ฅ)
        // 1. ์—ฐ, ์›” ๊ฒฐ์ •
        int year = myCalendar.getCurrent()[0];
        int month = myCalendar.getCurrent()[1];
        // 2. ์›” ๊ฐ€์ง€๊ณ  ์ตœ๋Œ€์ผ ๊ฒฐ์ • (2์›”์ด๋ฉด ์œค๋…„ test, ์œค๋…„์ด๋ฉด ์ตœ๋Œ€์ผ๋ฐฐ์—ด=dayDataLeapYear)
        int dayMax = 0;
        int[] dayData = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[] dayDataLeapYear = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        boolean leapTest = isLeapYear(year);
        if (month == 2 && leapTest == true) { //2์›”์ด๊ณ  ์œค๋…„
            dayMax = dayDataLeapYear[month - 1];
        }
        if (month == 2 && leapTest == false) { //2์›”์ด์ง€๋งŒ ์œค๋…„X
            dayMax = dayData[month - 1];
        }
        if (month != 2) { // 2์›” ์•„๋‹˜
            dayMax = dayData[month - 1];
        }
        // 3. ์›”์˜ 1์ผ์˜ ์š”์ผ ๊ณ„์‚ฐ
        int dayWeek1 = calMonth1stDayWeek(year, month); // ํ˜„์žฌ ์›”์˜ 1์ผ์˜ ์š”์ผ
        // 4. ๋‹ฌ๋ ฅ ํ˜•ํƒœ๋กœ ์ถœ๋ ฅ - printCalendar
        printCalendar(year, month, dayMax, dayWeek1);
    }

    public void buildPastCalendar(int year, int month){
        // (์—ฐ, ์›”์„ ์ž…๋ ฅ๋ฐ›์œผ๋ฉด ๊ทธ ์—ฐ, ์›”์˜ ๋‹ฌ๋ ฅ์„ ์ถœ๋ ฅ.)
        // 1. ์—ฐ, ์›” ๊ฒฐ์ • = ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›์•„์˜ด
        // 2. ์›” ๊ฐ€์ง€๊ณ  ์ตœ๋Œ€์ผ ๊ฒฐ์ • (2์›”์ด๋ฉด ์œค๋…„ test, ์œค๋…„์ด๋ฉด ์ตœ๋Œ€์ผ๋ฐฐ์—ด=dayDataLeapYear)
        int dayMax = 0;
        int[] dayData = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[] dayDataLeapYear = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        boolean leapTest = isLeapYear(year);
        if (month == 2 && leapTest == true) { //2์›”์ด๊ณ  ์œค๋…„
            dayMax = dayDataLeapYear[month - 1];
        }
        if (month == 2 && leapTest == false) { //2์›”์ด์ง€๋งŒ ์œค๋…„X
            dayMax = dayData[month - 1];
        }
        if (month != 2) { // 2์›” ์•„๋‹˜
            dayMax = dayData[month - 1];
        }
        // 3. ์›”์˜ 1์ผ์˜ ์š”์ผ ๊ณ„์‚ฐ
        int dayWeek1 = calMonth1stDayWeek(year, month); // ๊ธฐ์ค€ ์›”์˜ 1์ผ์˜ ์š”์ผ
        // 4. ๋‹ฌ๋ ฅ ํ˜•ํƒœ๋กœ ์ถœ๋ ฅ - printCalendar
        printCalendar(year, month, dayMax, dayWeek1);
    }

    public void printCalendar(int year, int month, int dayMax, int dayWeek1) {
        // ์›”์˜ 1์ผ์˜ ์š”์ผ๋ถ€ํ„ฐ(dayWeek1) 1~์ตœ๋Œ€์ผ ์ถœ๋ ฅ.
        System.out.println("========== " + year + "๋…„ " + month + "์›” ==========");
        System.out.println("  ์ผ  ์›”  ํ™”  ์ˆ˜  ๋ชฉ  ๊ธˆ  ํ†   ");
        for (int j = 1; j < dayWeek1; j++) {
            System.out.print(" โœจ "); //
        }
        for (int i = 1; i <= dayMax; i++) {
            if (i < 10) {// ํ•œ ์ž๋ฆฌ ์ˆ˜์ด๋ฉด ์•ž์— ๊ณต๋ฐฑ ํ•œ ๋ฒˆ ๋” ์ถ”๊ฐ€
                System.out.print("  " + i + " ");
            }
            if (i >= 10) {
                System.out.print(" " + i + " ");
            }
            // ์ค„๋ฐ”๊ฟˆ
            if ((dayWeek1 - 1 + i ) % 7 == 0) { // ๊ณต๋ฐฑ = (dayWeek1 - 1) + i ๊ฐ€ ์ผ์ฃผ์ผ ํ•œ ์ค„.
                System.out.println();//์ค„๋ฐ”๊ฟˆ
            }
        }
    }
}