System.out.println("태어난 연도를 입력하세요");
Scanner in=new Scanner(System.in);
int birthyear =in.nextInt();
String ddi="";
switch(birthyear%12) {
case 0 :ddi="원숭이"; break;
case 1 :ddi="닭"; break;
case 2 :ddi="개"; break;
case 3 :ddi="돼지"; break;
case 4 :ddi="쥐"; break;
case 5 :ddi="소"; break;
case 6 :ddi="호랑이"; break;
case 7 :ddi="토끼"; break;
case 8 :ddi="용"; break;
case 9 :ddi="뱀"; break;
case 10 :ddi="말"; break;
case 11:ddi="양"; break;
case가 참일때 스위치문을 끝내고 밑의 문장을 실행하지 않음
LocalDateTime today=LocalDateTime.now();
1.Date
Date today = new Date();
today.getFullTear(); -deplecate
today.getMonths();
today.getDate();
2.java 1.6 Calendar
Calendar.getInstance()
3.java 1.7 SimpleDateFormat
4.java 1.8 JoDaTime
5.java 1.11 LocalDateTime
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
LocalDateTime today=LocalDateTime.now();
String toDayStr = today.format(
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS"));
//2024-08-09 14:05:56:375(나노 세컨드)
System.out.println(toDayStr);
int year=today.getYear();
System.out.println(year+"년");//2024
int monval=today.getMonthValue();
System.out.println(monval+"달");//8월
int daymonths=today.getDayOfMonth();
System.out.println(daymonths +"일");//9일
int date=today.getDayOfYear();
System.out.println(date+"일");//222
DayOfWeek week=today.getDayOfWeek();
System.out.println(week+"요일");//FRIDAY
Month months=today.getMonth();
System.out.println("Months:"+months);//AUGUST*/
//올해 크리스마스 2000-12-25
LocalDateTime xmas=LocalDateTime.of(
2024,12,25,0,0,0);
String xmasStr=xmas.format(DateTimeFormatter.ofPattern(
"yyyy년 MM월 dd일 HH시 mm분 E요일"));
System.out.println(xmasStr);
참조:https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
'JAVA' 카테고리의 다른 글
[java] 반복문(for,while),등차∙피보나치∙등비 수열의 합 (0) | 2024.08.12 |
---|---|
[java] Stack메모리, Heap메모리 (0) | 2024.08.12 |
[java]가위바위보 게임 만들기(java programming),switch,random (0) | 2024.08.10 |
[java]성적 처리 프로그램 (Scanner사용) (0) | 2024.08.10 |
[java]-if문(조건 연산자),논리 연산자 처리 (0) | 2024.08.10 |