下面的时间默认是今日,如果是时间不是今日可以把new DateTime()替换成你的时间,但这个方法的前提类型是dataTime类型,结束后你可以toDate()转换为date类型,希望这个笔记能帮到大家!
如果有更好的方法,请不要默默离开
Date todayTime = new DateTime().withTimeAtStartOfDay().toDate();//今天凌晨
Date tomorrowTime = new DateTime().plusDays(1).withTimeAtStartOfDay().toDate();//昨日凌晨
Date theWeekStartTime = new DateTime().minusDays(new DateTime().getDayOfWeek()-1).withTimeAtStartOfDay().toDate();//本周开始时间
Date theWeekEndTime = new DateTime().plusDays(8-new DateTime().getDayOfWeek()).withTimeAtStartOfDay().toDate();//本周结束时间
Date theMonthStartTime = new DateTime().minusDays(new DateTime().getDayOfMonth()-1).withTimeAtStartOfDay().toDate();//本月开始时间
Date theMonthEndTime = new DateTime().minusDays(new DateTime().getDayOfMonth()-1).plusMonths(1).withTimeAtStartOfDay().toDate();//本月结束时间
如果有更好的方法,请不要默默离开

本文提供了使用newDateTime()方法进行日期操作的实用代码示例,包括获取今日、明日、本周及本月的开始与结束时间等,所有示例均以dataTime类型为基础,并通过toDate()转换为date类型。

806

被折叠的 条评论
为什么被折叠?



