本文整理汇总了Java中java.time.ZonedDateTime.ofInstant方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.ofInstant方法的具体用法?Java ZonedDateTime.ofInstant怎么用?Java ZonedDateTime.ofInstant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.ofInstant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: factory_ofInstant_minWithMaxOffset
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void factory_ofInstant_minWithMaxOffset() {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
int year = Year.MIN_VALUE;
long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L - OFFSET_MAX.getTotalSeconds());
ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MAX);
assertEquals(test.getYear(), Year.MIN_VALUE);
assertEquals(test.getMonth().getValue(), 1);
assertEquals(test.getDayOfMonth(), 1);
assertEquals(test.getOffset(), OFFSET_MAX);
assertEquals(test.getHour(), 0);
assertEquals(test.getMinute(), 0);
assertEquals(test.getSecond(), 0);
assertEquals(test.getNano(), 0);
}
示例2: start
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public synchronized void start() {
if (processThread != null) {
throw new IllegalStateException("Cannot re-start ticker handler.");
}
processThread = new Thread() {
public void run() {
try {
while (true) {
TickMessage tick = tickQueue.getMessage();
logger.info("Receive tick: " + tick);
store(tick, tick.time / 1000 == 0);
ZonedDateTime dt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(tick.time), DEFAULT_TIMEZONE);
list.add(dt.toLocalTime() + " $ " + tick.price + ", " + amount);
amount = amount.add(tick.amount);
}
} catch (InterruptedException e) {
logger.warn("TickerHandler was interrupted.");
}
// store unsaved ticker:
storeNow();
}
};
processThread.start();
}
示例3: convertTick
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private BaseTick convertTick(BittrexChartData data) {
return new BaseTick(ZonedDateTime.ofInstant(data.getTimeStamp().toInstant(), ZoneId.systemDefault()),
Decimal.valueOf(data.getOpen().toString()),
Decimal.valueOf(data.getHigh().toString()),
Decimal.valueOf(data.getLow().toString()),
Decimal.valueOf(data.getClose().toString()),
Decimal.valueOf(data.getVolume().toString()));
}
示例4: doLayout
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public String doLayout(ILoggingEvent event) {
Instant instant = Instant.ofEpochMilli(event.getTimeStamp());
ZonedDateTime dateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
StringBuilder log = new StringBuilder(dateTime.format(dateFormat));
log.append(String.format(" %-5s", event.getLevel().levelStr));
if (requireThread) {
log.append(String.format(" [%s]", event.getThreadName()));
}
int lineNumber = event.getCallerData().length > 0 ? event.getCallerData()[0].getLineNumber() : 0;
log.append(String.format(" %s:%d: ", event.getLoggerName(), lineNumber));
ThrowableProxy proxy = (ThrowableProxy) event.getThrowableProxy();
if (requireAlertLevel || requireErrorCode) {
appendExtraExceptionFlags(log, AbstractLoggingException.getFromThrowableProxy(proxy));
}
log.append(event.getFormattedMessage()).append(CoreConstants.LINE_SEPARATOR);
appendStackTrace(log, proxy);
if (proxy != null) {
loopCauses(log, proxy, 0);
}
return log.toString();
}
示例5: vanTimestampNaarZonedDateTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Geeft de {@link ZonedDateTime} waarde van een {@link Timestamp}.
* @param timestamp timestamp
* @return timestamp als zonedDateTime
*/
public static ZonedDateTime vanTimestampNaarZonedDateTime(final Timestamp timestamp) {
if (timestamp == null) {
return null;
}
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp.getTime()), DatumUtil.BRP_ZONE_ID);
}
示例6: run
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public void run() {
try {
while (true) {
Ticker ticker = tickerQueue.getMessage();
System.out.println("Message: " + ticker);
ZonedDateTime dt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(ticker.time), DEFAULT_TIMEZONE);
list.add(dt.toLocalTime() + " $ " + ticker.price + ", " + amount);
this.amount.addAndGet(ticker.amount);
}
} catch (InterruptedException e) {
}
}
示例7: getValue
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public final ZonedDateTime getValue(int index) {
final long value = values[index];
if (value == nullValue) {
return null;
} else {
final ZoneId zone = zoneIdMap2.get(zoneIds[index]);
final Instant instant = Instant.ofEpochMilli(value);
return ZonedDateTime.ofInstant(instant, zone);
}
}
示例8: deserialize
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public PoloniexChartData deserialize(JsonElement json, Type type, JsonDeserializationContext jdc) throws JsonParseException {
JsonObject jo = (JsonObject) json;
ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(jo.get("date").getAsLong() * 1000), ZoneOffset.UTC);
BigDecimal high = BigDecimal.valueOf(jo.get("high").getAsDouble());
BigDecimal low = BigDecimal.valueOf(jo.get("low").getAsDouble());
BigDecimal open = BigDecimal.valueOf(jo.get("open").getAsDouble());
BigDecimal close = BigDecimal.valueOf(jo.get("close").getAsDouble());
BigDecimal volume = BigDecimal.valueOf(jo.get("volume").getAsDouble());
BigDecimal quoteVolume = BigDecimal.valueOf(jo.get("quoteVolume").getAsDouble());
BigDecimal weightedAverage = BigDecimal.valueOf(jo.get("weightedAverage").getAsDouble());
return new PoloniexChartData(date, high, low, open, close, volume, quoteVolume, weightedAverage);
}
示例9: factory_ofInstant_tooLow
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_tooLow() {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
int year = Year.MIN_VALUE - 1;
long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
}
示例10: DateAsText
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Formats the date with ISO format using the system zone.
* @param date The date to format.
*/
public DateAsText(final Date date) {
this(
ZonedDateTime.ofInstant(date.toInstant(), ZoneId.of("UTC")),
new Iso().get()
);
}
示例11: castForDescriptor
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private static Object castForDescriptor(Object o, Class<?> type) {
if(o != null){
if(Long.class.isAssignableFrom(type)) {
return ((Number)o).longValue();
}
if(Integer.class.isAssignableFrom(type)) {
return ((Number)o).intValue();
}
if(Double.class.isAssignableFrom(type)) {
return ((Number)o).doubleValue();
}
if(Number.class.isAssignableFrom(type)) {
return ((Number)o).floatValue();
}
if(Boolean.class.isAssignableFrom(type)) {
return (Boolean) o;
}
if(ZonedDateTime.class.isAssignableFrom(type)) {
if(o instanceof Date){
return ZonedDateTime.ofInstant(((Date) o).toInstant(), ZoneId.of("UTC"));
}
return (ZonedDateTime) o;
}
if(Date.class.isAssignableFrom(type)) {
return (Date) o;
}
if(ByteBuffer.class.isAssignableFrom(type)) {
return ByteBuffer.wrap(new String((byte[]) o).getBytes()) ;
}
}
return o;
}
示例12: toZonedDateTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
protected ZonedDateTime toZonedDateTime(Date date) {
return date == null ? null : ZonedDateTime.ofInstant(date.toInstant(), ZoneId.of("UTC"));
}
示例13: getStartOfToday
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private static ZonedDateTime getStartOfToday() {
return ZonedDateTime.ofInstant(Instant.now().truncatedTo(ChronoUnit.DAYS), ZoneOffset.UTC);
}
示例14: factory_ofInstant_Instant_ZR
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void factory_ofInstant_Instant_ZR() {
Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 35).toInstant(OFFSET_0200);
ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
check(test, 2008, 6, 30, 11, 30, 10, 35, OFFSET_0200, ZONE_PARIS);
}
示例15: fromLong
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static ZonedDateTime fromLong(long value) {
Date date = new Date(value);
return ZonedDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC);
}