本文整理匯總了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;
}
}