本文整理汇总了Java中org.joda.time.Seconds.secondsBetween方法的典型用法代码示例。如果您正苦于以下问题:Java Seconds.secondsBetween方法的具体用法?Java Seconds.secondsBetween怎么用?Java Seconds.secondsBetween使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.Seconds
的用法示例。
在下文中一共展示了Seconds.secondsBetween方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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() + "");
}
示例3: getExamRemainingTime
import org.joda.time.Seconds; //导入方法依赖的package包/类
@Restrict({@Group("STUDENT")})
public Result getExamRemainingTime(String hash) throws IOException {
User user = getLoggedUser();
if (user == null) {
return forbidden("sitnet_error_invalid_session");
}
ExamEnrolment enrolment = Ebean.find(ExamEnrolment.class)
.fetch("reservation")
.fetch("reservation.machine")
.fetch("reservation.machine.room")
.fetch("exam")
.fetch("externalExam")
.where()
.disjunction()
.eq("exam.hash", hash)
.eq("externalExam.hash", hash)
.endJunction()
.eq("user.id", user.getId())
.findUnique();
if (enrolment == null) {
return notFound();
}
final DateTime reservationStart = new DateTime(enrolment.getReservation().getStartAt());
final int durationMinutes = getDuration(enrolment);
DateTime now = AppUtil.adjustDST(DateTime.now(), enrolment.getReservation());
final Seconds timeLeft = Seconds.secondsBetween(now, reservationStart.plusMinutes(durationMinutes));
return ok(String.valueOf(timeLeft.getSeconds()));
}
示例4: getSecondsUntilNextInterval
import org.joda.time.Seconds; //导入方法依赖的package包/类
public static Seconds getSecondsUntilNextInterval(int intervalInHours) {
DateTime currentDateTime = DateTime.now();
int hoursUntilNextInterval = (23 - currentDateTime.getHourOfDay()) % intervalInHours;
int hour = currentDateTime.getHourOfDay() + hoursUntilNextInterval;
DateTime scheduledTime = new DateTime(currentDateTime.getYear(), currentDateTime.getMonthOfYear(), currentDateTime.getDayOfMonth(), hour, 55, currentDateTime.getZone());
return Seconds.secondsBetween(currentDateTime, scheduledTime);
}
示例5: sessionTooOld
import org.joda.time.Seconds; //导入方法依赖的package包/类
private boolean sessionTooOld() {
Seconds secondsSinceLastSessionUpdate = Seconds.secondsBetween(sessionLastUpdated,
new DateTime(DateTimeZone.forID("EST5EDT")));
log.info("seconds since last session update: " + secondsSinceLastSessionUpdate.getSeconds());
if (secondsSinceLastSessionUpdate.getSeconds() > 240) {
return true;
}
return false;
}
示例6: scheduleAlarm
import org.joda.time.Seconds; //导入方法依赖的package包/类
private static void scheduleAlarm(DateTime alarmTime)
{
try
{
// Init playerthread
FileInputStream fis;
fis = new FileInputStream(selectedSong.getAbsolutePath());
BufferedInputStream bis = new BufferedInputStream(fis);
playerThread = new Mp3PlayerThread(bis);
// Schedule runnable.
Seconds seconds = Seconds.secondsBetween(new DateTime(), alarmTime);
Printer.debugMessage(
Main.class.getClass(),
String.format("alarm set in %d seconds",
seconds.getSeconds()));
// Schedule the task to execute at set date.
scheduler = Executors.newScheduledThreadPool(2);
scheduler.schedule(playerThread, seconds.getSeconds(),
TimeUnit.SECONDS);
} catch (FileNotFoundException e)
{
System.err.println("Invalid music file specified.");
System.exit(1);
}
}
示例7: on
import org.joda.time.Seconds; //导入方法依赖的package包/类
public void on(DateTime instant, Runnable runnable) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("schedule runnable[%s] on %s", runnable, instant);
}
DateTime now = DateTime.now();
E.illegalArgumentIf(instant.isBefore(now));
Seconds seconds = Seconds.secondsBetween(now, instant);
executor().schedule(wrap(runnable), seconds.getSeconds(), TimeUnit.SECONDS);
}
示例8: delayedSchedule
import org.joda.time.Seconds; //导入方法依赖的package包/类
private void delayedSchedule(JobManager manager, Job job) {
DateTime now = DateTime.now();
// add one seconds to prevent the next time be the current time (now)
DateTime next = cronExpr.nextTimeAfter(now.plusSeconds(1));
Seconds seconds = Seconds.secondsBetween(now, next);
ScheduledFuture future = manager.executor().schedule(job, seconds.getSeconds(), TimeUnit.SECONDS);
manager.futureScheduled(job.id(), future);
}
示例9: diffInSeconds
import org.joda.time.Seconds; //导入方法依赖的package包/类
private int diffInSeconds(DateTime a, DateTime b) {
Seconds diff;
if (a.isBefore(b)) {
diff = Seconds.secondsBetween(a, b);
} else {
diff = Seconds.secondsBetween(b, a);
}
return diff.getSeconds();
}
示例10: step
import org.joda.time.Seconds; //导入方法依赖的package包/类
@ScheduledMethod(start = 1.0, interval = 1.0, priority = -3000)
public void step() {
DateTime dateTime = new DateTime();
Seconds seconds = Seconds.secondsBetween(previous, dateTime);
Minutes minutes = Minutes.minutesBetween(previous, dateTime);
say("It took " + minutes.getMinutes() + " minutes and "
+ seconds.getSeconds() + " seconds between ticks.");
// check whether this is the last generation/iteration
if (currentIteration == (iterationNumber - 2)) {
if (currentGeneration == (generationNumber - 1)) {
say("Ending instance run");
RunEnvironment.getInstance().endRun();
}
}
if (currentIteration == (iterationNumber - 1)) {
say("This is the last iteration in this gen");
currentIteration = 0;
say("Ending current generation");
System.out.println(currentGeneration);
currentGeneration++;
} else {
say("Incrementing current iteration number to: "
+ (currentIteration + 1));
currentIteration++;
}
previous = new DateTime();
}
示例11: getRemainingTime
import org.joda.time.Seconds; //导入方法依赖的package包/类
protected static int getRemainingTime() {
DateTime now = DateTime.now();
Seconds pastTime = Seconds.secondsBetween(Context.getStartCurrentScenario(), now);
int totalTimecalculated = pastTime.getSeconds() * Context.getDataInputProvider().getNbGherkinExample() / Context.getCurrentScenarioData();
return totalTimecalculated - pastTime.getSeconds();
}
示例12: relative
import org.joda.time.Seconds; //导入方法依赖的package包/类
/**
* Returns a string indicating the distance between {@link DateTime}s. Defaults to comparing the input {@link DateTime} to
* the current time.
*/
public static @NonNull String relative(final @NonNull Context context, final @NonNull KSString ksString,
final @NonNull DateTime dateTime, final @NonNull RelativeDateTimeOptions options) {
final DateTime relativeToDateTime = ObjectUtils.coalesce(options.relativeToDateTime(), DateTime.now());
final Seconds seconds = Seconds.secondsBetween(dateTime, relativeToDateTime);
final int secondsDifference = seconds.getSeconds();
if (secondsDifference >= 0.0 && secondsDifference <= 60.0) {
return context.getString(R.string.dates_just_now);
} else if (secondsDifference >= -60.0 && secondsDifference <= 0.0) {
return context.getString(R.string.dates_right_now);
}
final Pair<String, Integer> unitAndDifference = unitAndDifference(secondsDifference, options.threshold());
if (unitAndDifference == null) {
// Couldn't find a good match, just render the date.
return mediumDate(dateTime);
}
final String unit = unitAndDifference.first;
final int difference = unitAndDifference.second;
boolean willHappenIn = false;
boolean happenedAgo = false;
if (!options.absolute()) {
if (secondsDifference < 0) {
willHappenIn = true;
} else if (secondsDifference > 0) {
happenedAgo = true;
}
}
if (happenedAgo && "days".equals(unit) && difference == 1) {
return context.getString(R.string.dates_yesterday);
}
final StringBuilder baseKeyPath = new StringBuilder();
if (willHappenIn) {
baseKeyPath.append(String.format("dates_time_in_%s", unit));
} else if (happenedAgo) {
baseKeyPath.append(String.format("dates_time_%s_ago", unit));
} else {
baseKeyPath.append(String.format("dates_time_%s", unit));
}
if (options.abbreviated()) {
baseKeyPath.append("_abbreviated");
}
return ksString.format(baseKeyPath.toString(), difference,
"time_count", NumberUtils.format(difference, NumberOptions.builder().build()));
}
示例13: jButton1ActionPerformed
import org.joda.time.Seconds; //导入方法依赖的package包/类
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
// If we have task scheduled cancel it.
if(scheduler != null)
{
playerThread.abortThread();
scheduler.shutdownNow();
}
// If we don't have a song scheduled, we cancel the task.
if (selectedSong == null)
{
Printer.debugMessage(this.getClass(), "No song selected");
} else
{
Printer.debugMessage(this.getClass(), "Selected: "
+ selectedSong.getAbsolutePath());
try
{
// Prepare the player thread.
FileInputStream fis = new FileInputStream(selectedSong.getAbsolutePath());
BufferedInputStream bis = new BufferedInputStream(fis);
playerThread = new Mp3PlayerThread(bis);
// Schedule runnable.
Seconds seconds = Seconds.secondsBetween(new DateTime(), alarmTime);
Printer.debugMessage(this.getClass(), String.format("alarm set in %d seconds", seconds.getSeconds()));
// Schedule the task to execute at set date.
scheduler = Executors.newScheduledThreadPool(2);
scheduler.schedule(playerThread, seconds.getSeconds(), TimeUnit.SECONDS);
Printer.debugMessage(this.getClass(), "alarm set at " + alarmTime);
// Update the label accordingly.
updateStatusLabel();
} catch (FileNotFoundException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
示例14: SecondsSinceDate
import org.joda.time.Seconds; //导入方法依赖的package包/类
public SecondsSinceDate(LocalDate epoch, LocalDateTime dateTime){
this(epoch, Seconds.secondsBetween(TypeUtil.toMidnight(epoch), dateTime));
}
示例15: seconds_between_two_dates_in_java_with_joda
import org.joda.time.Seconds; //导入方法依赖的package包/类
@Test
public void seconds_between_two_dates_in_java_with_joda () {
// start day is 1 day in the past
DateTime startDate = new DateTime().minusDays(1);
DateTime endDate = new DateTime();
Seconds seconds = Seconds.secondsBetween(startDate, endDate);
int secondsInDay = seconds.getSeconds();
assertEquals(86400, secondsInDay);
}