题解 | #3行代码,计算日期到天数转换#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
思路:
使用Calendar类计算
代码实现:
import java.util.Calendar; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int y=in.nextInt(); int m=in.nextInt(); int d=in.nextInt(); Calendar c1=Calendar.getInstance();//实例化 c1.set(y, m-1, d);//注意月份从0开始 System.out.println(c1.get(Calendar.DAY_OF_YEAR)); } }