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


Java ZonedDateTime.ofInstant方法代碼示例

本文整理匯總了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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:TCKZonedDateTime.java

示例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();
}
 
開發者ID:michaelliao,項目名稱:cryptoexchange,代碼行數:26,代碼來源:TickHandler.java

示例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()));
    }
 
開發者ID:jeperon,項目名稱:freqtrade-java,代碼行數:10,代碼來源:BittrexDataConverter.java

示例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();
}
 
開發者ID:hmcts,項目名稱:java-logging,代碼行數:33,代碼來源:ReformLoggingLayout.java

示例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);
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:12,代碼來源:DatumUtil.java

示例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) {

	}
}
 
開發者ID:michaelliao,項目名稱:crypto-exchange,代碼行數:15,代碼來源:Quotation.java

示例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);
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:13,代碼來源:DenseArrayOfZonedDateTimes.java

示例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);
}
 
開發者ID:TheCookieLab,項目名稱:poloniex-api-java,代碼行數:15,代碼來源:PoloniexChartDataDeserializer.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:TCKZonedDateTime.java

示例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()
    );
}
 
開發者ID:yegor256,項目名稱:cactoos,代碼行數:11,代碼來源:DateAsText.java

示例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;
        }
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:35,代碼來源:SolrUtils.java

示例12: toZonedDateTime

import java.time.ZonedDateTime; //導入方法依賴的package包/類
protected ZonedDateTime toZonedDateTime(Date date) {
    return date == null ? null : ZonedDateTime.ofInstant(date.toInstant(), ZoneId.of("UTC"));
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:4,代碼來源:OperationFactory.java

示例13: getStartOfToday

import java.time.ZonedDateTime; //導入方法依賴的package包/類
private static ZonedDateTime getStartOfToday() {
    return ZonedDateTime.ofInstant(Instant.now().truncatedTo(ChronoUnit.DAYS), ZoneOffset.UTC);
}
 
開發者ID:gchq,項目名稱:stroom-stats,代碼行數:4,代碼來源:GenerateSampleStatisticsData.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:TCKZonedDateTime.java

示例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);
}
 
開發者ID:EHRI,項目名稱:rs-aggregator,代碼行數:5,代碼來源:ZonedDateTimeUtil.java


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