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