简体   繁体   中英

Get week start timestamp and week end timestamp using Java SE API and Joda Time (based on ISO)

给定java.util.Date(或Joda DateTime),如何获得周开始时间戳(2010-03-01 00:00:00 UTC)和周结束时间戳(2010-03-08 00:00:00 UTC),还是年份和ISO周号,使用Java SE API和Joda Time?

JodaTime has support for ISO week numbers (see here ). For example:

java.util.Date date = new java.util.Date();
DateTime dateTime = new DateTime(date);
int isoWeek = dateTime.getWeekOfWeekyear();

You can also set the "start of aweek" using something like this:

DateTime startOfWeek = dateTime.withWeekOfWeekyear(4).withDayOfWeek(1).withTime(0, 0, 0, 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM