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


Java Instant.getEpochSecond方法代碼示例

本文整理匯總了Java中java.time.Instant.getEpochSecond方法的典型用法代碼示例。如果您正苦於以下問題:Java Instant.getEpochSecond方法的具體用法?Java Instant.getEpochSecond怎麽用?Java Instant.getEpochSecond使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.Instant的用法示例。


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

示例1: schedule

import java.time.Instant; //導入方法依賴的package包/類
@Scheduled(fixedRateString = "${schedule.interval}")
public void schedule()
{
	synchronized (scheduleContextQueue)
	{
		// Instant is in epoch time
		Instant nowInstant = Instant.now();
		long nowEpoch = nowInstant.getEpochSecond();

		// logger.debug("tick " + nowInstant.toString());

		while (scheduleContextQueue.peek() != null && scheduleContextQueue.peek().getNextTime().toEpochSecond() <= nowEpoch)
		{
			try {
				// pop the schedule context off the queue
				ScheduleContext scheduleContext = scheduleContextQueue.remove();

				logger.debug("executing schedule " + scheduleContext.getInfo() + " at " + scheduleContext.getNextTime());
				
				// run the events for the schedule
				scheduleEventExecutor.execute(scheduleContext.getScheduleEvents());

				// update the context 
				scheduleContext.updateNextTime();
				scheduleContext.updateIterations();

				// if the schedule is not complete, enqueue it.
				if(scheduleContext.isComplete()) {
					logger.info("schedule " + scheduleContext.getInfo() + " is complete." + scheduleContext.toString());
				} else {
					logger.debug("queueing schedule " + scheduleContext.getInfo());
					scheduleContextQueue.add(scheduleContext);
				}
			} catch (Exception e) {
				logger.error("exception while scheduling schedule contects" + e);
			}
		}
	}
}
 
開發者ID:edgexfoundry,項目名稱:device-modbus,代碼行數:40,代碼來源:Scheduler.java

示例2: schedule

import java.time.Instant; //導入方法依賴的package包/類
@Scheduled(fixedRateString = "${schedule.interval}")
public void schedule() {
  synchronized (scheduleContextQueue) {
    // Instant is in epoch time
    Instant nowInstant = Instant.now();
    long nowEpoch = nowInstant.getEpochSecond();

    // logger.debug("tick " + nowInstant.toString());

    while (scheduleContextQueue.peek() != null
        && scheduleContextQueue.peek().getNextTime().toEpochSecond() <= nowEpoch) {
      try {
        // pop the schedule context off the queue
        ScheduleContext scheduleContext = scheduleContextQueue.remove();

        logger.debug("executing schedule " + scheduleContext.getInfo() + " at "
            + scheduleContext.getNextTime());

        // run the events for the schedule
        scheduleEventExecutor.execute(scheduleContext.getScheduleEvents());

        // update the context
        scheduleContext.updateNextTime();
        scheduleContext.updateIterations();

        // if the schedule is not complete, enqueue it.
        if (scheduleContext.isComplete()) {
          logger.info("schedule " + scheduleContext.getInfo() + " is complete."
              + scheduleContext.toString());
        } else {
          logger.debug("queueing schedule " + scheduleContext.getInfo());
          scheduleContextQueue.add(scheduleContext);
        }
      } catch (Exception e) {
        logger.error("exception while scheduling schedule contects" + e);
      }
    }
  }
}
 
開發者ID:edgexfoundry,項目名稱:device-bluetooth,代碼行數:40,代碼來源:Scheduler.java

示例3: getStandardOffset

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Gets the standard offset for the specified instant in this zone.
 * <p>
 * This provides access to historic information on how the standard offset
 * has changed over time.
 * The standard offset is the offset before any daylight saving time is applied.
 * This is typically the offset applicable during winter.
 *
 * @param instant  the instant to find the offset information for, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the standard offset, not null
 */
public ZoneOffset getStandardOffset(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    long epochSec = instant.getEpochSecond();
    int index  = Arrays.binarySearch(standardTransitions, epochSec);
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    }
    return standardOffsets[index + 1];
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:ZoneRules.java

示例4: crAWebInput

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Creates a new Article object. www input, NNTP POST.
 * No message_id
 * 
 * @param thread_id - null if thread
 * @param a_name	may be null
 * @param subject	may be null
 * @param message	may be null
 * @param group
 * @param fileName may be null
 * @param contentType may be null
 * @return never null
 */
public static ArticleWebInput crAWebInput(Integer thread_id, String a_name, String subject, String message, Group group, String fileName, String contentType){
	Art a = new Art();
	
	if (a_name != null)
		if (a_name.isEmpty())
			a_name = null;
		else
			a.a_name = escapeString(a_name);
	
	if (subject != null)
		if (subject.isEmpty())
			subject = null;
		else
			a.subject = escapeString(subject);
	
	if (message != null)
		if (message.isEmpty())
			message = null;
		else
			message = message.replaceAll("\\s+$", ""); //we are more accurate with message. UTF-8 0 byte may appear..
	
	a.thread_id = thread_id;
	a.message = message;
	a.groupId = group.getInternalID(); //for input
	a.groupName = group.getName();
	Instant nowEpoch = Instant.now();        
	a.post_time = nowEpoch.getEpochSecond();
	a.msgID_host = Config.inst().get(Config.HOSTNAME, null);
	
	//TODO:check that .xxx is write and contentType == null with filename 
	a.fileName = fileName; //TODO make it .xxx - for very rare formats
	a.fileFormat = contentType; //if not null file exist
	
	generateHash(a);
	
	
	return new Article(a);
}
 
開發者ID:Anoncheg1,項目名稱:dibd,代碼行數:52,代碼來源:ArticleFactory.java

示例5: getOffset

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Gets the offset applicable at the specified instant in these rules.
 * <p>
 * The mapping from an instant to an offset is simple, there is only
 * one valid offset for each instant.
 * This method returns that offset.
 *
 * @param instant  the instant to find the offset for, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the offset, not null
 */
public ZoneOffset getOffset(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return standardOffsets[0];
    }
    long epochSec = instant.getEpochSecond();
    // check if using last rules
    if (lastRules.length > 0 &&
            epochSec > savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
        int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        ZoneOffsetTransition trans = null;
        for (int i = 0; i < transArray.length; i++) {
            trans = transArray[i];
            if (epochSec < trans.toEpochSecond()) {
                return trans.getOffsetBefore();
            }
        }
        return trans.getOffsetAfter();
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        // switch negative insert position to start of matched range
        index = -index - 2;
    }
    return wallOffsets[index + 1];
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:40,代碼來源:ZoneRules.java

示例6: convert

import java.time.Instant; //導入方法依賴的package包/類
@Override
public Long convert(final Instant value) {
  return value.getEpochSecond() * NANOS_PER_SECOND + value.getNano();
}
 
開發者ID:honnix,項目名稱:rkt-launcher,代碼行數:5,代碼來源:Time.java

示例7: marshal

import java.time.Instant; //導入方法依賴的package包/類
@Override
public Long marshal(Instant instant)
{
    return instant.getEpochSecond();
}
 
開發者ID:a-schild,項目名稱:nextcloud-java-api,代碼行數:6,代碼來源:InstantXmlAdapter.java

示例8: formatTime

import java.time.Instant; //導入方法依賴的package包/類
private static String formatTime(String prefix, Instant time) {
    return prefix + ": " + time + " - seconds: "
                    + time.getEpochSecond() + ", nanos: "
                    + time.getNano();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TestClock_System.java

示例9: testWithOffset

import java.time.Instant; //導入方法依賴的package包/類
static void testWithOffset(String name, long offset, Clock clock)
        throws IllegalAccessException {
    offsetField.set(clock, offset);
    long beforeMillis = System.currentTimeMillis();
    final Instant instant = clock.instant();
    long afterMillis = System.currentTimeMillis();
    long actualOffset = offsetField.getLong(clock);
    long instantMillis = instant.getEpochSecond() * MILLIS_IN_SECOND
            + instant.getNano() / NANOS_IN_MILLI;
    if (instantMillis < beforeMillis || instantMillis > afterMillis) {
        throw new RuntimeException(name
                + ": Invalid instant: " + instant
                + " (~" + instantMillis + "ms)"
                + " when time in millis is in ["
                + beforeMillis + ", " + afterMillis
                + "] and offset in seconds is " + offset);
    }
    Answer isOffLimits = isOffLimits(beforeMillis / MILLIS_IN_SECOND,
            afterMillis / MILLIS_IN_SECOND, offset);
    switch (isOffLimits) {
        case YES:
            if (actualOffset == offset) {
                throw new RuntimeException(name
                        + ": offset was offlimit but was not recomputed "
                        + " when time in millis is in ["
                        + beforeMillis + ", " + afterMillis
                        + "] and offset in seconds was " + offset);
            }
            break;
        case NO:
            if (actualOffset != offset) {
                throw new RuntimeException(name
                        + ": offset was not offlimit but was recomputed.");
            }
            break;
        default:
            break;
    }
    if (distance(actualOffset, instant.getEpochSecond()) >= MAX_OFFSET) {
        throw new RuntimeException(name + ": Actual offset is too far off:"
                + " offset=" + actualOffset
                + "instant.seconds=" + instant.getEpochSecond());
    }
    long adjustment = (instant.getEpochSecond() - actualOffset) * NANOS_IN_SECOND
            + instant.getNano();
    validateAdjustment(name, actualOffset, beforeMillis, afterMillis, adjustment);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:48,代碼來源:TestClock_System.java

示例10: previousTransition

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Gets the previous transition before the specified instant.
 * <p>
 * This returns details of the previous transition after the specified instant.
 * For example, if the instant represents a point where "summer" daylight saving time
 * applies, then the method will return the transition from the previous "winter" time.
 *
 * @param instant  the instant to get the previous transition after, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the previous transition after the specified instant, null if this is before the first transition
 */
public ZoneOffsetTransition previousTransition(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return null;
    }
    long epochSec = instant.getEpochSecond();
    if (instant.getNano() > 0 && epochSec < Long.MAX_VALUE) {
        epochSec += 1;  // allow rest of method to only use seconds
    }

    // check if using last rules
    long lastHistoric = savingsInstantTransitions[savingsInstantTransitions.length - 1];
    if (lastRules.length > 0 && epochSec > lastHistoric) {
        // search year the instant is in
        ZoneOffset lastHistoricOffset = wallOffsets[wallOffsets.length - 1];
        int year = findYear(epochSec, lastHistoricOffset);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        for (int i = transArray.length - 1; i >= 0; i--) {
            if (epochSec > transArray[i].toEpochSecond()) {
                return transArray[i];
            }
        }
        // use last from preceding year
        int lastHistoricYear = findYear(lastHistoric, lastHistoricOffset);
        if (--year > lastHistoricYear) {
            transArray = findTransitionArray(year);
            return transArray[transArray.length - 1];
        }
        // drop through
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        index = -index - 1;
    }
    if (index <= 0) {
        return null;
    }
    return new ZoneOffsetTransition(savingsInstantTransitions[index - 1], wallOffsets[index - 1], wallOffsets[index]);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:52,代碼來源:ZoneRules.java

示例11: previousTransition

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Gets the previous transition before the specified instant.
 * <p>
 * This returns details of the previous transition before the specified instant.
 * For example, if the instant represents a point where "summer" daylight saving time
 * applies, then the method will return the transition from the previous "winter" time.
 *
 * @param instant  the instant to get the previous transition after, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the previous transition before the specified instant, null if this is before the first transition
 */
public ZoneOffsetTransition previousTransition(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return null;
    }
    long epochSec = instant.getEpochSecond();
    if (instant.getNano() > 0 && epochSec < Long.MAX_VALUE) {
        epochSec += 1;  // allow rest of method to only use seconds
    }

    // check if using last rules
    long lastHistoric = savingsInstantTransitions[savingsInstantTransitions.length - 1];
    if (lastRules.length > 0 && epochSec > lastHistoric) {
        // search year the instant is in
        ZoneOffset lastHistoricOffset = wallOffsets[wallOffsets.length - 1];
        int year = findYear(epochSec, lastHistoricOffset);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        for (int i = transArray.length - 1; i >= 0; i--) {
            if (epochSec > transArray[i].toEpochSecond()) {
                return transArray[i];
            }
        }
        // use last from preceding year
        int lastHistoricYear = findYear(lastHistoric, lastHistoricOffset);
        if (--year > lastHistoricYear) {
            transArray = findTransitionArray(year);
            return transArray[transArray.length - 1];
        }
        // drop through
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        index = -index - 1;
    }
    if (index <= 0) {
        return null;
    }
    return new ZoneOffsetTransition(savingsInstantTransitions[index - 1], wallOffsets[index - 1], wallOffsets[index]);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:52,代碼來源:ZoneRules.java

示例12: from

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Obtains an instance of {@code Timestamp} from an {@link Instant} object.
 * <p>
 * {@code Instant} can store points on the time-line further in the future
 * and further in the past than {@code Date}. In this scenario, this method
 * will throw an exception.
 *
 * @param instant  the instant to convert
 * @return an {@code Timestamp} representing the same point on the time-line as
 *  the provided instant
 * @exception NullPointerException if {@code instant} is null.
 * @exception IllegalArgumentException if the instant is too large to
 *  represent as a {@code Timestamp}
 * @since 1.8
 */
public static Timestamp from(Instant instant) {
    try {
        Timestamp stamp = new Timestamp(instant.getEpochSecond() * MILLIS_PER_SECOND);
        stamp.nanos = instant.getNano();
        return stamp;
    } catch (ArithmeticException ex) {
        throw new IllegalArgumentException(ex);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:Timestamp.java

示例13: from

import java.time.Instant; //導入方法依賴的package包/類
/**
 * Obtains an instance of {@code Timestamp} from an {@link Instant} object.
 * <p>
 * {@code Instant} can store points on the time-line further in the future
 * and further in the past than {@code Date}. In this scenario, this method
 * will throw an exception.
 *
 * @param instant  the instant to convert
 * @return an {@code Timestamp} representing the same point on the time-line as
 *  the provided instant
 * @exception NullPointerException if {@code instant} is null.
 * @exception IllegalArgumentException if the instant is too large to
 *  represent as a {@code Timesamp}
 * @since 1.8
 */
public static Timestamp from(Instant instant) {
    try {
        Timestamp stamp = new Timestamp(instant.getEpochSecond() * MILLIS_PER_SECOND);
        stamp.nanos = instant.getNano();
        return stamp;
    } catch (ArithmeticException ex) {
        throw new IllegalArgumentException(ex);
    }
}
 
開發者ID:madHEYsia,項目名稱:ClassroomFlipkart,代碼行數:25,代碼來源:Timestamp.java


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