当前位置: 首页>>代码示例>>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;未经允许,请勿转载。