๐๋ ์ง,์๊ฐ ํด๋์ค
Calendar class => ์ถ์ ํด๋์ค
์ง์ ๊ฐ์ฒด๋ฅผ ์์ฑ ํ ์ ์์ = new์ฐ์ฐ์๋ฅผ ํตํด ๊ฐ์ฒด ๊ตฌํ์ด x
getInstance() ๋ฅผ ์ด์ฉํ์ฌ ๊ตฌํํ ํด๋์ค๋ฅผ ํตํด ์ธ์คํด์ค๋ฅผ ์ป์ด์ด
=> Calendar now = Calendar.getInstance();
month : 0์~11์ => ๋ฌด์กฐ๊ฑด +1ํ์
week : 1 = ์ผ์์ผ, 2 = ์์์ผ..
am_pm : am =0, pm=1
import java.util.Calendar;
import java.util.Date;
public class Date01 {
public static void main(String[] args) {
//1.Date clas
// Date d = new Date();
// d.getDate(); //depercated : ๋น๊ถ์ฅ
// System.out.println(d.getDate());
//2.Calendar class
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR); //๋
System.out.println(year);
int month = now.get(Calendar.MONTH)+1; //์ (๋จ,+1ํ์!!)
System.out.println(month);
int day = now.get(Calendar.DAY_OF_MONTH); //์ผ
System.out.println(day);
int week = now.get(Calendar.DAY_OF_WEEK); //์ฃผ
System.out.println(week); //=> ์ค๋์ ๊ธ์์ผ์ด๋ผ์ 6์ถ๋ ฅ
System.out.println(year + "-" + month + "-" + day);
//hour, minute, second
int hour = now.get(Calendar.HOUR);
System.out.println(hour);
int minute = now.get(Calendar.MINUTE);
System.out.println(minute);
int second = now.get(Calendar.SECOND);
System.out.println(second);
System.out.println(hour + ":" + minute + ":" + second);
//<์ถ๋ ฅ>
//2023-2-17(๊ธ)
//์คํ 3:10
String weekStr=null;
String am_pm;
switch (week){
case 2: weekStr="์"; break;
case 3: weekStr="ํ"; break;
case 4: weekStr="์"; break;
case 5: weekStr="๋ชฉ"; break;
case 6: weekStr="๊ธ"; break;
case 7: weekStr="ํ "; break;
default: weekStr="์ผ"; break;
}
if(Calendar.AM_PM == 0) {
am_pm = "์ค์ ";
} else {
am_pm = "์คํ";
}
//System.out.println((Calendar.AM_PM == 0)? "์ค์ ":"์คํ");
System.out.println(year+"-"+month+"-"+day+"("+weekStr+")");
System.out.println(am_pm + " " +hour+ ":" +minute);
}
}
'JAVA > java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] LocalDateTime (0) | 2023.03.26 |
---|---|
[JAVA] SimpleDateFormat (0) | 2023.03.26 |
[JAVA] Map ์ ์ฅ ๊ณต๊ฐ์ ๋ฐ๋ฅธ ์ด์ฉ๋ฒ (0) | 2023.03.26 |
[JAVA] ์ปฌ๋ ์ ํ๋ ์์ํฌ : Map (์์X, key์ค๋ณตX/Value์ค๋ณตO) (0) | 2023.03.26 |
[JAVA] ์ปฌ๋ ์ ํ๋ ์์ํฌ : Set (์ค๋ณตX, ์์X) (0) | 2023.03.26 |