当前位置: 首页>>代码示例>>Java>>正文


Java Seconds.secondsBetween方法代码示例

本文整理汇总了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);

}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:23,代码来源:CalculateDateTimeDifference.java

示例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() + "");
}
 
开发者ID:inter12,项目名称:swiftly,代码行数:26,代码来源:DateTools.java

示例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()));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:34,代码来源:TimeController.java

示例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);
}
 
开发者ID:mick0n,项目名称:minewrap,代码行数:8,代码来源:TimeUtil.java

示例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;

}
 
开发者ID:bullhorn,项目名称:starter-kit-spring-maven,代码行数:11,代码来源:BullhornAPISoap.java

示例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);
	}

}
 
开发者ID:m1dnight,项目名称:jalarm,代码行数:28,代码来源:Main.java

示例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);
}
 
开发者ID:actframework,项目名称:actframework,代码行数:10,代码来源:JobManager.java

示例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);
}
 
开发者ID:actframework,项目名称:actframework,代码行数:9,代码来源:JobTrigger.java

示例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();
}
 
开发者ID:solita,项目名称:kansalaisaloite,代码行数:10,代码来源:VetumaController.java

示例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();
}
 
开发者ID:ResearchGeek,项目名称:hyip-simulation,代码行数:30,代码来源:GameController.java

示例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();
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:7,代码来源:CucumberHooks.java

示例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()));
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:57,代码来源:DateTimeUtils.java

示例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();
		}
	}
}
 
开发者ID:m1dnight,项目名称:jalarm,代码行数:43,代码来源:AlarmFrame.java

示例14: SecondsSinceDate

import org.joda.time.Seconds; //导入方法依赖的package包/类
public SecondsSinceDate(LocalDate epoch, LocalDateTime dateTime){
	this(epoch, Seconds.secondsBetween(TypeUtil.toMidnight(epoch), dateTime));
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:4,代码来源:SecondsSinceDate.java

示例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);
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:14,代码来源:SecondsBetweenDates.java


注:本文中的org.joda.time.Seconds.secondsBetween方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。