本文整理汇总了Java中org.joda.time.DateTime.plusHours方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.plusHours方法的具体用法?Java DateTime.plusHours怎么用?Java DateTime.plusHours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.plusHours方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isInvasionTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
public boolean isInvasionTime(DateTime startDate, DateTime current) {
//For the record, the invasion times themselves are NOT random. They are 6 hours on, 12.5 hours off, repeating forever.
//This gives an invasion happening at every possible hour of the day over a 3 day period.
DateTime start = new DateTime(startDate);
boolean loop = true;
boolean enabled = true;
while (loop) {
if (enabled) {
start = start.plusHours(6);
if (current.isBefore(start)) {
loop = false;
} else {
enabled = false;
}
} else {
start = start.plusHours(12).plusMinutes(30);
if (current.isBefore(start)) {
loop = false;
} else {
enabled = true;
}
}
}
return enabled;
}
示例2: getIncrementUrl
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public String getIncrementUrl(Market market) {
if (market == null) {
return null;
}
// http://img.yingyonghui.com/interface/ijinshan/ijinshan_on_{day}_{hour}.csv.gz
DateTime dt = new DateTime(market.getIncrementLastTime());
dt = dt.plusHours(1);
String date = new java.text.SimpleDateFormat("yyyyMMdd_H").format(dt.toDate());
String incrementApiUrl = market.getIncrementUrl();
StringBuilder url = new StringBuilder(incrementApiUrl.length());
url.append(incrementApiUrl);
if (!incrementApiUrl.endsWith("/")) {
url.append("/");
}
url.append("ijinshan_on_");
url.append(date);
url.append(".csv.gz");
url.append("?t=");
url.append(System.currentTimeMillis());
final String fileUrl = url.toString();
logger.info("AppChina : {}", fileUrl);
return fileUrl;
}
示例3: getIncrementUrl
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public String getIncrementUrl(Market market) {
if (market == null) {
return null;
}
// http://www.yingyong.so/shoujikong/ijinshan_shoujikong_on_{day}_{hour}.csv.gz
DateTime dt = new DateTime(market.getIncrementLastTime());
dt = dt.plusHours(1);
String date = new java.text.SimpleDateFormat("yyyyMMdd_H").format(dt.toDate());
String incrementApiUrl = market.getIncrementUrl();
StringBuilder url = new StringBuilder(incrementApiUrl.length());
url.append(incrementApiUrl);
if (!incrementApiUrl.endsWith("/")) {
url.append("/");
}
url.append("ijinshan_shoujikong_on_");
url.append(date);
url.append(".csv.gz");
url.append("?t=");
url.append(System.currentTimeMillis());
logger.debug("URL : {}", url.toString());
return url.toString();
}
示例4: getIncrementUrl
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public String getIncrementUrl(Market market) {
if (market == null) {
return null;
}
// http://apk.91.com/data/ijinshan_on_{day}_{hour}.csv
DateTime dt = new DateTime(market.getIncrementLastTime());
dt = dt.plusHours(1);
String date = new java.text.SimpleDateFormat("yyyyMMdd_H").format(dt.toDate());
String incrementApiUrl = market.getIncrementUrl();
StringBuilder url = new StringBuilder(incrementApiUrl.length());
url.append(incrementApiUrl);
if (!incrementApiUrl.endsWith("/")) {
url.append("/");
}
url.append("ijinshan_on_");
url.append(date);
url.append(".csv.gz");
url.append("?t=");
url.append(System.currentTimeMillis());
return url.toString();
}
示例5: getIncrementUrl
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public String getIncrementUrl(Market market) {
if (market == null) {
return null;
}
// http://www.yingyong.so/shoujikong/ijinshan_on_{day}_{hour}.csv.gz
DateTime dt = new DateTime(market.getIncrementLastTime());
dt = dt.plusHours(1);
String date = new java.text.SimpleDateFormat("yyyyMMdd_H").format(dt.toDate());
String incrementApiUrl = market.getIncrementUrl();
StringBuilder url = new StringBuilder(incrementApiUrl.length());
url.append(incrementApiUrl);
if (!incrementApiUrl.endsWith("/")) {
url.append("/");
}
url.append("ijinshan_on_");
url.append(date);
url.append(".csv.gz");
url.append("?t=");
url.append(System.currentTimeMillis());
return url.toString();
}
示例6: createEvent_defaultCalendar
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Test
public void createEvent_defaultCalendar() throws CalendarWriteException, IOException {
//given
final String summary = "<summary>";
final DateTime from = DateTime.now();
final DateTime to = from.plusHours(1);
Map<String, CalendarCLIAdapter> calendar = new HashMap<>();
calendar.put("default", mock(CalendarCLIAdapter.class));
calendar.put("sec", mock(CalendarCLIAdapter.class));
CalendarConfiguration.NAME_OF_DEFAULT_CALENDAR = "default";
doReturn(calendar).when(toTest).getCalendars();
doReturn("<uid-def>").when(calendar.get("default")).createEvent(any(), any(), any());
doReturn("<uid-sec>").when(calendar.get("sec")).createEvent(any(), any(), any());
//when
final String result = toTest.createEvent(null, summary, from, to);
//then
assertEquals("<uid-def>", result);
verify(calendar.get("default"), times(1)).createEvent(
same(summary), same(from), same(to)
);
verify(calendar.get("sec"), never()).createEvent(any(), any(), any());
}
示例7: createEvent_customCalendar
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Test
public void createEvent_customCalendar() throws CalendarWriteException, IOException {
//given
final String summary = "<summary>";
final DateTime from = DateTime.now();
final DateTime to = from.plusHours(1);
Map<String, CalendarCLIAdapter> calendar = new HashMap<>();
calendar.put("default", mock(CalendarCLIAdapter.class));
calendar.put("sec", mock(CalendarCLIAdapter.class));
CalendarConfiguration.NAME_OF_DEFAULT_CALENDAR = "default";
doReturn(calendar).when(toTest).getCalendars();
doReturn("<uid-def>").when(calendar.get("default")).createEvent(any(), any(), any());
doReturn("<uid-sec>").when(calendar.get("sec")).createEvent(any(), any(), any());
//when
final String result = toTest.createEvent("sec", summary, from, to);
//then
assertEquals("<uid-sec>", result);
verify(calendar.get("sec"), times(1)).createEvent(
same(summary), same(from), same(to)
);
verify(calendar.get("default"), never()).createEvent(any(), any(), any());
}
示例8: createEvent_calendarThrowsException
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Test(expected = CalendarWriteException.class)
public void createEvent_calendarThrowsException() throws CalendarWriteException, IOException {
//given
final String summary = "<summary>";
final DateTime from = DateTime.now();
final DateTime to = from.plusHours(1);
Map<String, CalendarCLIAdapter> calendar = new HashMap<>();
calendar.put("default", mock(CalendarCLIAdapter.class));
CalendarConfiguration.NAME_OF_DEFAULT_CALENDAR = "default";
doReturn(calendar).when(toTest).getCalendars();
doThrow(new IOException()).when(calendar.get("default")).createEvent(any(), any(), any());
//when
toTest.createEvent(null, summary, from, to);
}
示例9: prepareIndex
import org.joda.time.DateTime; //导入方法依赖的package包/类
private void prepareIndex(DateTime date, int numHours, int stepSizeHours, int idxIdStart) throws IOException, InterruptedException, ExecutionException {
IndexRequestBuilder[] reqs = new IndexRequestBuilder[numHours];
for (int i = idxIdStart; i < idxIdStart + reqs.length; i++) {
reqs[i - idxIdStart] = client().prepareIndex("idx2", "type", "" + i).setSource(jsonBuilder().startObject().field("date", date).endObject());
date = date.plusHours(stepSizeHours);
}
indexRandom(true, reqs);
}
示例10: testSingleValueWithTimeZone
import org.joda.time.DateTime; //导入方法依赖的package包/类
public void testSingleValueWithTimeZone() throws Exception {
prepareCreate("idx2").addMapping("type", "date", "type=date").execute().actionGet();
IndexRequestBuilder[] reqs = new IndexRequestBuilder[5];
DateTime date = date("2014-03-11T00:00:00+00:00");
for (int i = 0; i < reqs.length; i++) {
reqs[i] = client().prepareIndex("idx2", "type", "" + i).setSource(jsonBuilder().startObject().field("date", date).endObject());
date = date.plusHours(1);
}
indexRandom(true, reqs);
SearchResponse response = client().prepareSearch("idx2")
.setQuery(matchAllQuery())
.addAggregation(dateHistogram("date_histo")
.field("date")
.timeZone(DateTimeZone.forID("-02:00"))
.dateHistogramInterval(DateHistogramInterval.DAY)
.format("yyyy-MM-dd:HH-mm-ssZZ"))
.execute().actionGet();
assertThat(response.getHits().getTotalHits(), equalTo(5L));
Histogram histo = response.getAggregations().get("date_histo");
List<? extends Histogram.Bucket> buckets = histo.getBuckets();
assertThat(buckets.size(), equalTo(2));
Histogram.Bucket bucket = buckets.get(0);
assertThat(bucket, notNullValue());
assertThat(bucket.getKeyAsString(), equalTo("2014-03-10:00-00-00-02:00"));
assertThat(bucket.getDocCount(), equalTo(2L));
bucket = buckets.get(1);
assertThat(bucket, notNullValue());
assertThat(bucket.getKeyAsString(), equalTo("2014-03-11:00-00-00-02:00"));
assertThat(bucket.getDocCount(), equalTo(3L));
}
示例11: testTimePlus
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 时间加减操作,plus 负数时是向前推移
*/
@Test
public void testTimePlus() {
// 获取当前时间
DateTime dt = new DateTime();
String currentTime = dt.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("currentTime: " + currentTime);
// 相对当前时间 向后5天,5天后
DateTime plus5Days = dt.plusDays(5);
String plus5DaysStr = plus5Days.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("plus 5 days: " + plus5DaysStr);
// 相对当前时间 向后5个小时,5小时后
DateTime plus5Hours = dt.plusHours(5);
String plus5HoursStr = plus5Hours.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("plus 5 hours: " + plus5HoursStr);
// 相对当前时间,向后5分钟,5分钟后
DateTime plus5Minutes = dt.plusMinutes(5);
String plus5MinutesStr = plus5Minutes.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("plus 5 minutes: " + plus5MinutesStr);
// 相对当前时间,向前5年,5年前
DateTime plus5Years = dt.plusYears(-5);
String plus5YearsStr = plus5Years.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("5 years ago: " + plus5YearsStr);
// 相对当前时间,向前5个月
DateTime plusMonths = dt.plusMonths(-5);
String plusMonthsStr = plusMonths.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("5 month ago: " + plusMonthsStr);
}
示例12: createDefaultStartingHours
import org.joda.time.DateTime; //导入方法依赖的package包/类
private static List<ExamStartingHour> createDefaultStartingHours(String roomTz) {
// Get offset from Jan 1st in order to no have DST in effect
DateTimeZone zone = DateTimeZone.forID(roomTz);
DateTime beginning = DateTime.now().withDayOfYear(1).withTimeAtStartOfDay();
DateTime ending = beginning.plusHours(LAST_HOUR);
List<ExamStartingHour> hours = new ArrayList<>();
while (!beginning.isAfter(ending)) {
ExamStartingHour esh = new ExamStartingHour();
esh.setStartingHour(beginning.toDate());
esh.setTimezoneOffset(zone.getOffset(beginning));
hours.add(esh);
beginning = beginning.plusHours(1);
}
return hours;
}
示例13: adjustDST
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static DateTime adjustDST(DateTime dateTime, ExternalReservation externalReservation) {
DateTime result = dateTime;
DateTimeZone dtz = DateTimeZone.forID(externalReservation.getRoomTz());
if (!dtz.isStandardOffset(System.currentTimeMillis())) {
result = dateTime.plusHours(1);
}
return result;
}
示例14: doAdjustDST
import org.joda.time.DateTime; //导入方法依赖的package包/类
private static DateTime doAdjustDST(DateTime dateTime, ExamRoom room) {
DateTimeZone dtz;
DateTime result = dateTime;
if (room == null) {
dtz = getDefaultTimeZone();
} else {
dtz = DateTimeZone.forID(room.getLocalTimezone());
}
if (!dtz.isStandardOffset(System.currentTimeMillis())) {
result = dateTime.plusHours(1);
}
return result;
}
示例15: secondsUntilNextMondayRun
import org.joda.time.DateTime; //导入方法依赖的package包/类
private int secondsUntilNextMondayRun() {
DateTime now = DateTime.now();
// Every Monday at 5AM UTC
int adjustedHours = 5;
if (!AppUtil.getDefaultTimeZone().isStandardOffset(now.getMillis())) {
// Have the run happen an hour earlier to take care of DST offset
adjustedHours -= 1;
}
DateTime nextRun = now.withHourOfDay(adjustedHours)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0)
.plusWeeks(now.getDayOfWeek() == DateTimeConstants.MONDAY ? 0 : 1)
.withDayOfWeek(DateTimeConstants.MONDAY);
if (!nextRun.isAfter(now)) {
nextRun = nextRun.plusWeeks(1); // now is a Monday after scheduled run time -> postpone
}
// Case for: now there's no DST but by next run there will be.
if (adjustedHours == 5 && !AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
nextRun = nextRun.minusHours(1);
}
// Case for: now there's DST but by next run there won't be
else if (adjustedHours != 5 && AppUtil.getDefaultTimeZone().isStandardOffset(nextRun.getMillis())) {
nextRun = nextRun.plusHours(1);
}
Logger.info("Scheduled next weekly report to be run at {}", nextRun.toString());
// Increase delay with one second so that this won't fire off before intended time. This may happen because of
// millisecond-level rounding issues and possibly cause resending of messages.
return Seconds.secondsBetween(now, nextRun).getSeconds() + 1;
}