本文整理汇总了Java中org.threeten.bp.Instant.toEpochMilli方法的典型用法代码示例。如果您正苦于以下问题:Java Instant.toEpochMilli方法的具体用法?Java Instant.toEpochMilli怎么用?Java Instant.toEpochMilli使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.Instant
的用法示例。
在下文中一共展示了Instant.toEpochMilli方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processSubscriptionDataEvent
import org.threeten.bp.Instant; //导入方法依赖的package包/类
private void processSubscriptionDataEvent(Event event, Session session) throws Exception {
s_logger.debug("Processing SUBSCRIPTION_DATA");
if (tickWriterIsAlive()) {
MessageIterator msgIter = event.messageIterator();
while (msgIter.hasNext()) {
Message msg = msgIter.next();
if (isValidMessage(msg)) {
String securityDes = (String) msg.correlationID().object();
MutableFudgeMsg tickMsg = s_fudgeContext.newMessage();
Instant instant = Clock.systemUTC().instant();
long epochMillis = instant.toEpochMilli();
tickMsg.add(RECEIVED_TS_KEY, epochMillis);
tickMsg.add(SECURITY_KEY, securityDes);
tickMsg.add(FIELDS_KEY, BloombergDataUtils.parseElement(msg.asElement()));
s_logger.debug("{}: {} - {}", new Object[]{_dateFormat
.format(Calendar.getInstance().getTime()), securityDes, msg.messageType()});
s_logger.debug("{}", msg.asElement());
_allTicksQueue.put(tickMsg);
s_logger.debug("singleQueueSize {}", _allTicksQueue.size());
}
}
} else {
stopTickCollection();
}
}
示例2: doSnapshot
import org.threeten.bp.Instant; //导入方法依赖的package包/类
private void doSnapshot(Map<String, String> ticker2Buid) {
ReferenceDataProvider refDataProvider = _refDataProvider;
Map<String, FudgeMsg> refDataValues = refDataProvider.getReferenceDataIgnoreCache(ticker2Buid.keySet(), BloombergDataUtils.STANDARD_FIELDS_SET);
for (String bloombergKey : ticker2Buid.keySet()) {
FudgeMsg result = refDataValues.get(bloombergKey);
if (result == null) {
throw new OpenGammaRuntimeException("Result for " + bloombergKey + " was not found");
}
MutableFudgeMsg tickMsg = s_fudgeContext.newMessage();
Instant instant = Clock.systemUTC().instant();
long epochMillis = instant.toEpochMilli();
tickMsg.add(RECEIVED_TS_KEY, epochMillis);
tickMsg.add(SECURITY_KEY, bloombergKey);
tickMsg.add(FIELDS_KEY, result);
tickMsg.add(BUID_KEY, ticker2Buid.get(bloombergKey));
try {
_allTicksQueue.put(tickMsg);
} catch (InterruptedException ex) {
Thread.interrupted();
throw new OpenGammaRuntimeException("Unable to do snaphot for " + bloombergKey, ex);
}
}
}
示例3: runOneCycle
import org.threeten.bp.Instant; //导入方法依赖的package包/类
@Override
protected void runOneCycle() {
s_logger.debug("queueSize {} ", _writerQueue.size());
for (String security : _securities) {
int msgSize = _messageSizeGenerator.nextInt(MAX_MESSAGE_SIZE);
for (int i = 0; i < msgSize; i++) {
try {
MutableFudgeMsg msg = getRandomMessage();
Instant instant = Clock.systemUTC().instant();
long epochMillis = instant.toEpochMilli();
msg.add(RECEIVED_TS_KEY, epochMillis);
msg.add(SECURITY_KEY, security);
s_logger.debug("generating {}", msg);
_writerQueue.put(msg);
} catch (InterruptedException e) {
Thread.interrupted();
s_logger.warn("interrupted exception while putting ticks message on queue");
}
}
}
}
示例4: getDifferenceInYears
import org.threeten.bp.Instant; //导入方法依赖的package包/类
/**
* Returns endDate - startDate in years, where a year is defined as 365.25 days.
*
* @param startDate the start date, not null
* @param endDate the end date, not null
* @return the difference in years
* @throws IllegalArgumentException if either date is null
*/
public static double getDifferenceInYears(final Instant startDate, final Instant endDate) {
if (startDate == null) {
throw new IllegalArgumentException("Start date was null");
}
if (endDate == null) {
throw new IllegalArgumentException("End date was null");
}
return (double) (endDate.toEpochMilli() - startDate.toEpochMilli()) / MILLISECONDS_PER_YEAR;
}
示例5: instantToTaiMillisSince2004Mod32
import org.threeten.bp.Instant; //导入方法依赖的package包/类
/** Returns TAI milliseconds mod 2^32 for the given date.
*
* Since java int is signed 32 bit integer, return long instead.
* It is the same on byte level, but just to avoid confusing people with negative values here.
*
*
* From http://stjarnhimlen.se/comp/time.html:
*
* TAI (Temps Atomique International or International Atomic Time) is
* defined as the weighted average of the time kept by about 200
* atomic clocks in over 50 national laboratories worldwide.
* TAI-UT1 was approximately 0 on 1958 Jan 1.
* (TAI is ahead of UTC by 35 seconds as of 2014.)
*
* GPS time = TAI - 19 seconds. GPS time matched UTC from 1980-01-01
* to 1981-07-01. No leap seconds are inserted into GPS time, thus
* GPS time is 13 seconds ahead of UTC on 2000-01-01. The GPS epoch
* is 00:00 (midnight) UTC on 1980-01-06.
* The difference between GPS Time and UTC changes in increments of
* seconds each time a leap second is added to UTC time scale.
*/
public static long instantToTaiMillisSince2004Mod32(Instant instantX) {
OffsetDateTime gnEpochStart =
OffsetDateTime.of(LocalDateTime.of(2004, Month.JANUARY, 1, 0, 0), ZoneOffset.UTC);
long millis2004 = gnEpochStart.toInstant().toEpochMilli();
long millisAtX = instantX.toEpochMilli();
long taiMillis = (millisAtX + LEAP_SECONDS_SINCE_2004*1000) - millis2004;
return taiMillis % (1L << 32);
}