本文整理汇总了Java中org.joda.time.DateTimeZone.nextTransition方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeZone.nextTransition方法的具体用法?Java DateTimeZone.nextTransition怎么用?Java DateTimeZone.nextTransition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateTimeZone
的用法示例。
在下文中一共展示了DateTimeZone.nextTransition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
@Override
public ServerTimeZoneResponse execute(ServerTimeZoneRequest request, SessionContext context) {
Date first = null, last = null;
for (Session session: SessionDAO.getInstance().findAll()) {
if (first == null || first.after(session.getEventBeginDate()))
first = session.getEventBeginDate();
if (last == null || last.before(session.getEventEndDate()))
last = session.getEventEndDate();
}
DateTimeZone zone = DateTimeZone.getDefault();
int offsetInMinutes = zone.getOffset(first.getTime()) / 60000;
ServerTimeZoneResponse ret = new ServerTimeZoneResponse();
ret.setId(zone.getID());
ret.addName(zone.getName(new Date().getTime()));
ret.setTimeZoneOffsetInMinutes(offsetInMinutes);
long time = first.getTime();
long transition;
while (time != (transition = zone.nextTransition(time)) && time < last.getTime()) {
int adjustment = (zone.getOffset(transition) / 60000) - offsetInMinutes;
ret.addTransition((int)(transition / 3600000), adjustment);
time = transition;
}
return ret;
}
示例2: nastyDate
import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
/**
* To be even more nasty, go to a transition in the selected time zone.
* In one third of the cases stay there, otherwise go half a unit back or forth
*/
private static long nastyDate(long initialDate, DateTimeZone timezone, long unitMillis) {
long date = timezone.nextTransition(initialDate);
if (randomBoolean()) {
return date + (randomLong() % unitMillis); // positive and negative offset possible
} else {
return date;
}
}