티스토리 뷰

package com.aa;

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

public class ThisWeek {

public static void main(String[] args) {
String dateString = "20190719";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
try{
date = sdf.parse(dateString);
System.out.println("date="+date);
}catch(ParseException e){
}
Calendar cal = Calendar.getInstance(Locale.KOREA);
cal.setTime(date);

System.out.println("입력한 날짜 : "+sdf.format(cal.getTime()));
cal.add(Calendar.DATE, 2 - cal.get(Calendar.DAY_OF_WEEK));
System.out.println("첫번째 요일(월요일)날짜:"+sdf.format(cal.getTime()));
cal.setTime(date);
cal.add(Calendar.DATE, 8 - cal.get(Calendar.DAY_OF_WEEK));
System.out.println("마지막 요일(일요일)날짜:"+sdf.format(cal.getTime()));
}
}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함