编程语言
首页 > 编程语言> > Java 计算今天是这周的第几天 这月 这年

Java 计算今天是这周的第几天 这月 这年

作者:互联网

Calendar calendar = Calendar.getInstance();
//时间,可以为具体的某一时间
Date today = new Date();
calendar.setTime(today);
int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
int yearDay = calendar.get(Calendar.DAY_OF_YEAR);
if (weekDay == 1) {
weekDay = 7;
} else {
weekDay = weekDay - 1;
}
System.out.println("当前时间是,本周的第" + weekDay + "天");
System.out.println("当前时间是,本月的第" + monthDay + "天");
System.out.println("当前时间是,本年的第" + yearDay + "天");

标签:Java,第几天,int,System,这年,weekDay,Calendar,calendar,out
来源: https://www.cnblogs.com/xiaobug/p/16528238.html