날짜를 입력하여 해당 연도의 며칠째를 보십시오

9917 단어 시간 조작
코드는 다음과 같습니다.
/*
 *       ,      :
	(1)           ,  (2015-10-20)
	(2)                 
	(3)   :2015-10-20,  "2015 -10 -20       ,   2015    293  "
 * */

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

public class Work {
	public static void main(String[] args) throws ParseException {
		Scanner input = new Scanner(System.in);
		System.out.println("       ,   :2000-01-01");
		String str = input.nextLine();
		Date date = new Date();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		date = df.parse(str);
		Calendar cd = Calendar.getInstance();
		cd.setTime(date);
		int week = cd.get(Calendar.DAY_OF_WEEK);
		String str2 = chineseWeek(week);
		int year = cd.get(Calendar.YEAR);
		int month = cd.get(Calendar.MONTH) + 1;
		int day = cd.get(Calendar.DAY_OF_MONTH);
		long num = cd.getTimeInMillis();
		//System.out.println(num);
		cd.set(year,0,0);
		long num1 = cd.getTimeInMillis();
		//System.out.println(num1);
		long num2 = (num - num1) / 1000 / 60 / 60 / 24;
		System.out.println(year + " -" + month + " -" + day + "    " 
				           + str2 + ", " + year + "   " + num2 + " ");
		
		
		
	}

	private static String chineseWeek(int week) {
		String[] str = {"   ","   ","   ","   ","   ","   ","   "};
		return str[week - 1];
	}
}

좋은 웹페이지 즐겨찾기