需求:键盘录入一个日期字符串,程序输出这个日期是一年中的第多少天
package com.bingyi.date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class CalendarDemo2 { public static void main(String[] args) throws ParseException { extracted(); } private static void extracted() throws ParseException { Scanner sc = new Scanner(System.in); System.out.println(""); String dateContent = sc.nextLine(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); Date date = simpleDateFormat.parse(dateContent); Calendar c = Calendar.getInstance(); c.setTime(date); int dayOfYear = c.get(Calendar.YEAR); System.out.println(dayOfYear); } }