Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Java 获取今年第一天和最后一天] #java #日期处理
public static String getYearBegin(){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH,calendar.getMinimum(Calendar.MONTH));
calendar.set(Calendar.DAY_OF_MONTH,calendar.getMinimum(Calendar.DAY_OF_MONTH));
return DateUtils.getDateStrByFormat(calendar.getTime(),"yyyy-MM-dd");
}
public static String getYearEnd(){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH,calendar.getMaximum(Calendar.MONTH));
calendar.set(Calendar.DAY_OF_MONTH,calendar.getMaximum(Calendar.DAY_OF_MONTH));
return DateUtils.getDateStrByFormat(calendar.getTime(),"yyyy-MM-dd");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.