- import java.util.Calendar;
- import java.util.Scanner;
- class GetDayDemo
- {
- //键盘读取一个日期,格式为 1999-02-25
- public static void main(String[] args)
- {
- //键盘获取
- Scanner sc = new Scanner(System.in);
- String line = sc.nextLine();
- //切割成数组
- String[] date = line.split("-");
- int year = Integer.parseInt(date[0]);
- int month = Integer.parseInt(date[1])-1;
- int day = Integer.parseInt(date[2]);
- //设置时间
- Calendar c = Calendar.getInstance();
- c.set(year,month,day);
- //得到结果
- int result = c.get(Calendar.DAY_OF_YEAR);
- System.out.println(result);
- }
- }
复制代码 |