- import java.io.IOException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Scanner;
- public class DateDemo {
- public static void main(String[] args) throws IOException
- {
-
- Scanner in = new Scanner(System.in);
-
- String date = in.next();
-
- SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd");
-
- try {
- Date dt = df.parse(date);
-
- Calendar cd = Calendar.getInstance();
-
- cd.setTime(dt);
-
- System.out.println( "星期:"+(cd.get(Calendar.DAY_OF_WEEK)-1));
- System.out.println( "一年中的第"+cd.get(Calendar.DAY_OF_YEAR) +"天");
-
-
- } catch (ParseException e) {
-
- e.printStackTrace();
- }
- }
- }
复制代码
|