當前位置: 首頁>>代碼示例>>Java>>正文


Java Seconds類代碼示例

本文整理匯總了Java中org.joda.time.Seconds的典型用法代碼示例。如果您正苦於以下問題:Java Seconds類的具體用法?Java Seconds怎麽用?Java Seconds使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Seconds類屬於org.joda.time包,在下文中一共展示了Seconds類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: withinSecondsAfter

import org.joda.time.Seconds; //導入依賴的package包/類
public static Matcher<String> withinSecondsAfter(Seconds seconds, DateTime after) {
    return new TypeSafeMatcher<String>() {
      @Override
      public void describeTo(Description description) {
        description.appendText(String.format(
          "a date time within %s seconds after %s",
          seconds.getSeconds(), after.toString()));
      }

      @Override
      protected boolean matchesSafely(String textRepresentation) {
        //response representation might vary from request representation
        DateTime actual = DateTime.parse(textRepresentation);

        return actual.isAfter(after) &&
          Seconds.secondsBetween(after, actual).isLessThan(seconds);
      }
    };
}
 
開發者ID:folio-org,項目名稱:mod-circulation-storage,代碼行數:20,代碼來源:TextDateTimeMatcher.java

示例2: sendResponse

import org.joda.time.Seconds; //導入依賴的package包/類
private static void sendResponse(
        Channel channel, SocketAddress remoteAddress, ChannelBuffer id, int index, int report) {

    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.dynamicBuffer();
        response.writeBytes("SM".getBytes(StandardCharsets.US_ASCII));
        response.writeByte(3); // protocol version
        response.writeByte(MSG_DATE_RECORD_ACK);
        response.writeBytes(id);
        response.writeInt(Seconds.secondsBetween(
                new DateTime(2000, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(DateTimeZone.UTC)).getSeconds());
        response.writeByte(index);
        response.writeByte(report - 0x200);

        short checksum = (short) 0xF5A0;
        for (int i = 0; i < response.readableBytes(); i += 2) {
            checksum ^= ChannelBuffers.swapShort(response.getShort(i));
        }
        response.writeShort(checksum);

        channel.write(response, remoteAddress);
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:24,代碼來源:SmokeyProtocolDecoder.java

示例3: mergeFile

import org.joda.time.Seconds; //導入依賴的package包/類
public static void mergeFile() {
    String rootPath = "D:/bdsoft/vko/tianli_act_code";
    String destPath = rootPath + "/all_code.txt";

    File rootDir = new File(rootPath);
    if (rootDir.exists()) {
        File[] fileArr = rootDir.listFiles();
        DateTime start = new DateTime();
        System.out.println("開始:" + start.toLocalDateTime());
        for (File file : fileArr) {
            readFrom(destPath, file);
        }
        DateTime end = new DateTime();
        System.out.println("結束:" + end.toLocalDateTime());
        String msg = String.format("文件合並完畢,耗時:%s分 %s秒", (Minutes.minutesBetween(start, end).getMinutes() % 60),
                (Seconds.secondsBetween(start, end).getSeconds() % 3600));
        System.out.println(msg);
    }
}
 
開發者ID:bdceo,項目名稱:bd-codes,代碼行數:20,代碼來源:TianliActCode.java

示例4: computeTimeModeAndDiff

import org.joda.time.Seconds; //導入依賴的package包/類
private int computeTimeModeAndDiff(DateTime dmin, DateTime dmax) {
    int diffDay = Days.daysBetween(dmin, dmax).getDays();
    int diffHou = Hours.hoursBetween(dmin, dmax).getHours();
    int diffMin = Minutes.minutesBetween(dmin, dmax).getMinutes();
    int diffSec = Seconds.secondsBetween(dmin, dmax).getSeconds();

    int diff = diffMin;

    guessTimeMode(diffDay, diffHou, diffMin, diffSec);

    if (TimeMode.DAY.equals(timeMode)) {
        diff = diffDay;
    } else if (TimeMode.HOUR.equals(timeMode)) {
        diff = diffHou;
    } else if (TimeMode.MINUTE.equals(timeMode)) {
        diff = diffMin;
    } else if (TimeMode.SECOND.equals(timeMode)) {
        diff = diffSec;
    }

    //consoleDiffs(diffDay, diffHou, diffMin, diffSec, diff);

    return diff;
}
 
開發者ID:jzy3d,項目名稱:bigpicture,代碼行數:25,代碼來源:HistogramDate.java

示例5: pollIfLimitReached

import org.joda.time.Seconds; //導入依賴的package包/類
@RequestMapping("/poll")
@ResponseBody
public boolean pollIfLimitReached(@RequestAttribute User loggedUser) {
    if (loggedUser == null) {
        return false;
    }
    ActivitySession session = map.get(loggedUser.getId());
    // no atomicity required, hence getting & putting sequentially
    if (session == null) {
        session = new ActivitySession();
        session.setStart(new DateTime());
        map.put(loggedUser.getId(), session);
    }

    // warn the user only once per session
    if (loggedUser.getProfile().isWarnOnMinutesPerDayLimit() && !session.isUserWarned()) {
        // the time today = the time save in the DB + the time of the current session so far
        int onlineSecondsToday = loggedUser.getOnlineSecondsToday() + Seconds.secondsBetween(session.getStart(), new DateTime()).getSeconds();
        if (loggedUser.getProfile().getMinutesOnlinePerDay() * 60 < onlineSecondsToday) {
            session.setUserWarned(true);
            return true;
        }
    }

    return false;
}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:27,代碼來源:UserActivityController.java

示例6: onExpiry

import org.joda.time.Seconds; //導入依賴的package包/類
@Override
@SqlTransactional
public void onExpiry(String userId, ActivitySession session) {

    User user = getDao().getById(User.class, userId);
    logger.debug("Expiring activity session of user: " + user);
    session.setUser(user);
    session.setEnd(new DateTime());
    session.setSeconds(Seconds.secondsBetween(session.getStart(), session.getEnd()).getSeconds());
    save(session);

    if (user.getProfile().isWarnOnMinutesPerDayLimit()) {
        int secondsToday = user.getOnlineSecondsToday();
        if (shouldResetOnlineSecondsToday(user)) {
            secondsToday = 0;
        }
        secondsToday += session.getSeconds();
        user.setOnlineSecondsToday(secondsToday);
    }
}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:21,代碼來源:ActivitySessionService.java

示例7: dateToAge

import org.joda.time.Seconds; //導入依賴的package包/類
private static String dateToAge(String createdAt, DateTime now) {
    if (createdAt == null) {
        return "";
    }

    DateTimeFormatter dtf = DateTimeFormat.forPattern(DATE_TIME_FORMAT);
    try {
        DateTime created = dtf.parseDateTime(createdAt);

        if (Seconds.secondsBetween(created, now).getSeconds() < 60) {
            return Seconds.secondsBetween(created, now).getSeconds() + "s";
        } else if (Minutes.minutesBetween(created, now).getMinutes() < 60) {
            return Minutes.minutesBetween(created, now).getMinutes() + "m";
        } else if (Hours.hoursBetween(created, now).getHours() < 24) {
            return Hours.hoursBetween(created, now).getHours() + "h";
        } else {
            return Days.daysBetween(created, now).getDays() + "d";
        }
    } catch (IllegalArgumentException e) {
        return "";
    }
}
 
開發者ID:zfoltin,項目名稱:twittererer,代碼行數:23,代碼來源:TimelineConverter.java

示例8: create

import org.joda.time.Seconds; //導入依賴的package包/類
@Override
public Object create(Object request, SpecimenContext context) {

    if (!(request instanceof SpecimenType)) {
        return new NoSpecimen();
    }

    SpecimenType type = (SpecimenType) request;
    if (!BaseSingleFieldPeriod.class.isAssignableFrom(type.getRawType())) {
        return new NoSpecimen();
    }

    Duration duration = (Duration) context.resolve(Duration.class);
    if (type.equals(Seconds.class)) return Seconds.seconds(Math.max(1, (int) duration.getStandardSeconds()));
    if (type.equals(Minutes.class)) return Minutes.minutes(Math.max(1, (int) duration.getStandardMinutes()));
    if (type.equals(Hours.class)) return Hours.hours(Math.max(1, (int) duration.getStandardHours()));

    if (type.equals(Days.class)) return Days.days(Math.max(1, (int) duration.getStandardDays()));
    if (type.equals(Weeks.class)) return Weeks.weeks(Math.max(1, (int) duration.getStandardDays() / 7));
    if (type.equals(Months.class)) return Months.months(Math.max(1, (int) duration.getStandardDays() / 30));
    if (type.equals(Years.class)) return Years.years(Math.max(1, (int) duration.getStandardDays() / 365));

    return new NoSpecimen();
}
 
開發者ID:FlexTradeUKLtd,項目名稱:jfixture,代碼行數:25,代碼來源:BaseSingleFieldPeriodRelay.java

示例9: validate

import org.joda.time.Seconds; //導入依賴的package包/類
/**
 * Validate an access_token.
 * The Oauth2 specification does not specify how this should be done. Do similar to what Google does
 *
 * @param access_token access token to validate. Be careful about using url safe tokens or use url encoding.
 * @return http 200 if success and some basic info about the access_token
 */
@GET
@Path("tokeninfo")
public Response validate(@QueryParam("access_token") String access_token) {
  checkNotNull(access_token);

  DConnection connection = connectionDao.findByAccessToken(access_token);
  LOGGER.debug("Connection {}", connection);
  if (null == connection || hasAccessTokenExpired(connection)) {
    throw new BadRequestRestException("Invalid access_token");
  }

  return Response.ok(ImmutableMap.builder()
      .put("user_id", connection.getUserId())
      .put("expires_in", Seconds.secondsBetween(DateTime.now(), new DateTime(connection.getExpireTime())).getSeconds())
      .build())
      .build();

}
 
開發者ID:Wadpam,項目名稱:guja,代碼行數:26,代碼來源:OAuth2AuthorizationResource.java

示例10: difference_between_two_dates_joda

import org.joda.time.Seconds; //導入依賴的package包/類
@Test
public void difference_between_two_dates_joda () {
	
	DateTime sinceGraduation = new DateTime(1984, 6, 4, 0, 0, GregorianChronology.getInstance());
	DateTime currentDate = new DateTime(); //current date

	Days diffInDays = Days.daysBetween(sinceGraduation, currentDate);
	Hours diffInHours = Hours.hoursBetween(sinceGraduation, currentDate);
	Minutes diffInMinutes = Minutes.minutesBetween(sinceGraduation, currentDate);
	Seconds seconds = Seconds.secondsBetween(sinceGraduation, currentDate);
	
	logger.info(diffInDays.getDays());
	logger.info(diffInHours.getHours());
	logger.info(diffInMinutes.getMinutes());
	logger.info(seconds.getSeconds());
	
	assertTrue(diffInDays.getDays() >= 10697);
	assertTrue(diffInHours.getHours() >= 256747);
	assertTrue(diffInMinutes.getMinutes() >= 15404876);
	assertTrue(seconds.getSeconds() >= 924292577);

}
 
開發者ID:wq19880601,項目名稱:java-util-examples,代碼行數:23,代碼來源:CalculateDateTimeDifference.java

示例11: buildFields

import org.joda.time.Seconds; //導入依賴的package包/類
private Map<String, Object> buildFields(FlowLogMessage msg) {
    return new HashMap<String, Object>() {{
        put("account_id", msg.getAccountId());
        put("interface_id", msg.getInterfaceId());
        put("src_addr", msg.getSourceAddress());
        put("dst_addr", msg.getDestinationAddress());
        put("src_port", msg.getSourcePort());
        put("dst_port", msg.getDestinationPort());
        put("protocol_number", msg.getProtocolNumber());
        put("protocol", protocolNumbers.lookup(msg.getProtocolNumber()));
        put("packets", msg.getPackets());
        put("bytes", msg.getBytes());
        put("capture_window_duration_seconds", Seconds.secondsBetween(msg.getCaptureWindowStart(), msg.getCaptureWindowEnd()).getSeconds());
        put("action", msg.getAction());
        put("log_status", msg.getLogStatus());
    }};
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-aws,代碼行數:18,代碼來源:CloudWatchFlowLogCodec.java

示例12: shouldIgnoreNotification

import org.joda.time.Seconds; //導入依賴的package包/類
private boolean shouldIgnoreNotification(@NotNull final Notification notification) {
    Notification lastNotification = mOrmManager.getLastNotification();
    if (lastNotification == null) {
        return false;
    }

    boolean result = false;
    if (notification.getTitle().equals(lastNotification.getTitle())) {
        if (notification.getText().equals(lastNotification.getText())) {
            if (Seconds.secondsBetween(lastNotification.getCreated(), notification.getCreated()).getSeconds() < 60) {
                result = true;
            }
        }
    }

    return result;
}
 
開發者ID:nhaarman,項目名稱:PebbleNotifier,代碼行數:18,代碼來源:MyNotificationListenerService.java

示例13: toSecondsSinceDate

import org.joda.time.Seconds; //導入依賴的package包/類
/**
 * @see DataType#DATE_TIME_SECONDS_SINCE_1960
 * @see DataType#DATE_TIME_SECONDS_SINCE_1970
 * @see DataType#DATE_TIME_SECONDS_SINCE_1980
 */
static
private SecondsSinceDate toSecondsSinceDate(Object value, LocalDate epoch){

	if(value instanceof SecondsSinceDate){
		SecondsSinceDate period = (SecondsSinceDate)value;

		if((period.getEpoch()).equals(epoch)){
			return period;
		}

		Seconds difference = Seconds.secondsBetween(toMidnight(epoch), toMidnight(period.getEpoch())).plus(period.getSeconds());

		return new SecondsSinceDate(epoch, difference);
	}

	throw new TypeCheckException(getSecondsDataType(epoch), value);
}
 
開發者ID:jpmml,項目名稱:jpmml-evaluator,代碼行數:23,代碼來源:TypeUtil.java

示例14: sniffTest

import org.joda.time.Seconds; //導入依賴的package包/類
@Test
public void sniffTest() {
    final RDBI rdbi = new RDBI(new JedisPool("localhost"));

    final Map<String, RedisCacheTest.TestContainer> rMap = new RedisMap<>(RedisCacheTest.keyGenerator,
                                                                         RedisCacheTest.helper,
                                                                         rdbi,
                                                                         "mycache" + UUID.randomUUID().toString(),
                                                                         cachePrefix,
                                                                         Seconds.seconds(60).toStandardDuration());

    final RedisCacheTest.TestContainer value1 = new RedisCacheTest.TestContainer(UUID.randomUUID());
    final RedisCacheTest.TestContainer value2 = new RedisCacheTest.TestContainer(UUID.randomUUID());

    rMap.put("value1", value1);
    rMap.put("value2", value2);

    assertEquals(rMap.get("value1"), value1);
    assertEquals(rMap.get("value2"), value2);
}
 
開發者ID:lithiumtech,項目名稱:rdbi,代碼行數:21,代碼來源:RedisMapTest.java

示例15: compare

import org.joda.time.Seconds; //導入依賴的package包/類
public void compare() {
    DateTime dateTime1 = new DateTime(2014, 1, 1, 12, 00, 00);
    DateTime dateTime2 = new DateTime(2014, 1, 1, 12, 00, 01);

    // 時間之間的比較
    boolean after = dateTime2.isAfter(dateTime1);
    LOGGER.info("is after" + after);

    // 兩個時間之間相差的秒數
    Seconds seconds = Seconds.secondsBetween(dateTime1, dateTime2);
    LOGGER.info(seconds.getSeconds() + "");

    LOGGER.info("1:" + dateTime1.toString(YYYY_MM_DD_HH_MM_SS));
    LOGGER.info("2:" + dateTime2.toString(YYYY_MM_DD_HH_MM_SS));

    // 兩個時間之間xiang相差的天數
    Days days = Days.daysBetween(dateTime1, dateTime2);
    LOGGER.info("second:" + days.toStandardDuration().getStandardSeconds());

    LOGGER.info(days.get(DurationFieldType.hours()) + "");
    LOGGER.info(days.getFieldType().getName());
    LOGGER.info(days.getPeriodType().getName());
    LOGGER.info(days.toStandardSeconds().getSeconds() + "");
    LOGGER.info(days.getDays() + "");
}
 
開發者ID:inter12,項目名稱:swiftly,代碼行數:26,代碼來源:DateTools.java


注:本文中的org.joda.time.Seconds類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。