本文整理匯總了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);
}
};
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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 "";
}
}
示例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();
}
示例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();
}
示例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);
}
示例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());
}};
}
示例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;
}
示例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);
}
示例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);
}
示例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() + "");
}