This question already has an answer here:
这个问题在这里已有答案:
- How to get day of year number in Java for a specific date object? [duplicate] 3 answers
- Today is nth day of year [duplicate] 6 answers
如何在Java中获取特定日期对象的年份数? [重复] 3个答案
今天是一年中的第n天[重复] 6个答案
Is there a way to get the date in java in days only? For instance Jan 1 would equal 1 and Feb 1 would equal 32? Instead of the standard time format yyyy/mm/dd? Perhaps by editing the date formater somehow:
有没有办法在几天内在java中获取日期?例如Jan 1等于1,2月1等于32?而不是标准时间格式yyyy / mm / dd?也许通过某种方式编辑日期格式化程序:
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate localDate = LocalDate.now();
4 个解决方案
#1
1
Use getDayOfYear()
:
LocalDate localDate = LocalDate.now();
System.out.println(localDate.getDayOfYear());
Returns: the day-of-year, from 1 to 365, or 366 in a leap year
返回:年份,从1到365,或闰年为366
#2
0
You can use below
你可以在下面使用
Calendar calendar = Calendar.getInstance(); int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
日历日历= Calendar.getInstance(); int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
#3
0
int day = LocalDate.getDayOfYear();
int day = LocalDate.getDayOfYear();
#4
0
try this
SimpleDateFormat format1=new SimpleDateFormat("MM/dd/yyyy");
Date dt1=format1.parse(pass your date);
DateFormat format2=new SimpleDateFormat("EEEE");
String finalDay=format2.format(dt1);
#1
1
Use getDayOfYear()
:
LocalDate localDate = LocalDate.now();
System.out.println(localDate.getDayOfYear());
Returns: the day-of-year, from 1 to 365, or 366 in a leap year
返回:年份,从1到365,或闰年为366
#2
0
You can use below
你可以在下面使用
Calendar calendar = Calendar.getInstance(); int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
日历日历= Calendar.getInstance(); int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
#3
0
int day = LocalDate.getDayOfYear();
int day = LocalDate.getDayOfYear();
#4
0
try this
SimpleDateFormat format1=new SimpleDateFormat("MM/dd/yyyy");
Date dt1=format1.parse(pass your date);
DateFormat format2=new SimpleDateFormat("EEEE");
String finalDay=format2.format(dt1);