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


Java Instant類代碼示例

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


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

示例1: exportCsv

import java.time.Instant; //導入依賴的package包/類
/**
 * Export result to csv
 *
 * @param requestParams the query of the transfer timing search
 * @param pageable      the pagination information
 * @return downloadable csv
 */
@GetMapping(value = "/transfer-timings.csv", produces = CsvMediaType.TEXT_CSV_VALUE)
@Timed
public ResponseEntity<List<TransferTimingListingDTO>> exportCsv(@RequestParam Map<String, String> requestParams, @ApiParam Pageable pageable) {
    /* ==========================
     * In this example you might not understand as I did not put the other part of code but I have a AbstractHttpMessageConverter
     * that converts object or list of objects to a CSV
     * ==========================
     */
    final List<TransferTimingListingDTO> list;

    if (requestParams != null) {
        list = transferTimingPageService.searchWithoutPaging(requestParams, pageable);
    } else {
        list = transferTimingPageService.getAllWithoutPaging(pageable);
    }

    String filename = "visual-timings-" + Instant.now().getEpochSecond() + ".csv";

    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + filename);
    headers.add("X-Save-As", filename);

    return new ResponseEntity<>(list, headers, HttpStatus.OK);
}
 
開發者ID:Blackdread,項目名稱:filter-sort-jooq-api,代碼行數:32,代碼來源:TransferTimingPageResource.java

示例2: testCloseWithoutPersistedFile

import java.time.Instant; //導入依賴的package包/類
@Test(expected = ChronicleHashClosedException.class)
public void testCloseWithoutPersistedFile() {
  MetricStore heapStore = new VarBitMetricStore();
  long uuid1 = 1;
  long ts = Instant.now().getEpochSecond();
  double value = 100;

  heapStore.addPoint(uuid1, ts, value);
  OffHeapVarBitMetricStore offheapStore1 =
      OffHeapVarBitMetricStore.toOffHeapStore(getSeriesMap(heapStore), testFileName, "");

  assertEquals(1, offheapStore1.getSeriesMap().size());
  List<Point> points = offheapStore1.getSeries(uuid1);
  assertEquals(1, points.size());
  assertEquals(ts, points.get(0).getTs());
  assertEquals(value, points.get(0).getVal(), delta);

  offheapStore1.close();
  offheapStore1.getSeriesMap().size();
}
 
開發者ID:pinterest,項目名稱:yuvi,代碼行數:21,代碼來源:OffHeapVarBitMetricStoreTest.java

示例3: build

import java.time.Instant; //導入依賴的package包/類
private synchronized _BridgeSubscription build(String subId, String sourceMxId, Instant timestamp, String email, String threadId, String mxId, String roomId) {
    log.info("Creating new subscription {} for email {} with threadId {} and matrix id {} in room {}",
            subId,
            email,
            threadId,
            mxId,
            roomId);

    _EmailEndPoint emEp = emMgr.getEndpoint(email, threadId);
    _MatrixEndPoint mxEp = mxMgr.getEndpoint(mxId, roomId);
    String eKey = emMgr.getKey(email, threadId);
    String mKey = mxMgr.getKey(mxId, roomId);

    _BridgeSubscription sub = new BridgeSubscription(subId, sourceMxId, timestamp, formatter, eKey, emEp, mKey, mxEp);
    sub.addListener(this::remove);

    subs.put(subId, sub);
    subsEmailKey.put(eKey, new WeakReference<>(sub));
    subsMatrixKey.put(mKey, new WeakReference<>(sub));

    return sub;
}
 
開發者ID:kamax-io,項目名稱:matrix-appservice-email,代碼行數:23,代碼來源:SubscriptionManager.java

示例4: testImageCapture2

import java.time.Instant; //導入依賴的package包/類
@Test
public void testImageCapture2() throws IOException {
    AVFImageCaptureService service = AVFImageCaptureService.getInstance();
    AVFImageCapture ic = service.getImageCapture();
    String[] devices = ic.videoDevicesAsStrings();
    if (devices.length > 0) {
        ic.startSessionWithNamedDevice(devices[0]);
        Path path = Paths.get("target",
                getClass().getSimpleName() + "-1-" + Instant.now() + ".png");
        Optional<Image> png = ic.capture(path.toFile());
        ic.stopSession();
        Assert.assertTrue(png.isPresent());

    }
    else {
        System.err.println("No frame capture devices were found");
    }
}
 
開發者ID:mbari-media-management,項目名稱:vars-annotation,代碼行數:19,代碼來源:AVFImageCaptureServiceTest.java

示例5: changeCloseConditionsOfOrder

import java.time.Instant; //導入依賴的package包/類
@Override
public Optional<Failed> changeCloseConditionsOfOrder(final CloseConditions conditions) {
    final Optional<Failed> failed = orderManagement.changeCloseConditionsOfOrder(conditions);

    final Instant time = currentTime.get();
    events.add(new TradeEvent(CLOSE_CONDITIONS_CHANGED, time, "expert advisor changed close conditions",
            conditions));
    if (failed.isPresent()) {
        events.add(new TradeEvent(CLOSE_CONDITIONS_CHANGED, time,
                "broker faild to changed close conditions of expert advisor: " + failed.get(),
                currentCloseConditions));
    } else {
        currentCloseConditions = conditions;
    }

    return failed;
}
 
開發者ID:rbi,項目名稱:trading4j,代碼行數:18,代碼來源:TradeTracker.java

示例6: addDateRangeRule

import java.time.Instant; //導入依賴的package包/類
/**
 * Helper method to add a DateRange Commission Rule to the Commission ruleset.
 * Should only be called from getCommissionRuleSetWithDateRanges.
 */
private static Builder<RuleSetBuilder, DecisionTreeRuleSet> addDateRangeRule(
        final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder,
        final String startDate, final String endDate,
        final String exmethod, final String exchange,
        final String product, final String region,
        final String asset, final Instant start,
        final Instant finish, final long ruleId, final String rate) {
    return ruleSetBuilder.with(RuleSetBuilder::rule, RuleBuilder.creator()
            .with(RuleBuilder::input, Arrays.asList("DR:" + startDate + "|" + endDate,
                    exmethod, exchange, product, region, asset))
            .with(RuleBuilder::start, start)
            .with(RuleBuilder::end, finish)
            .with(RuleBuilder::setId, new UUID(0L, ruleId))
            .with(RuleBuilder::setCode, new UUID(0L, ruleId))
            .with(RuleBuilder::output, Collections.singletonMap("Rate", rate)));
}
 
開發者ID:jpmorganchase,項目名稱:swblocks-decisiontree,代碼行數:21,代碼來源:CommisionRuleSetSupplier.java

示例7: connect

import java.time.Instant; //導入依賴的package包/類
private final int connect(int times) {
    times++;
    if(times > reconnection_tries) {
        instant_started = null;
        return times;
    }
    try {
        StaticStandard.log(String.format("[CLIENT] Started connecting to %s (Try: %d)", formatAddressAndPort(), times));
        socket = new Socket(inetaddress, port);
        setSocket(socket);
        instant_started = Instant.now();
        connected = true;
        if(!isServerClient) {
            send(MessageState.LOGIN);
        }
        disconnected = false;
        StaticStandard.log("[CLIENT] Connected successfully to " + formatAddressAndPort());
    } catch (Exception ex) {
        StaticStandard.logErr("[CLIENT] Error while connecting to server: " + ex);
        instant_started = null;
    }
    isConnected(times);
    return times;
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:25,代碼來源:Client.java

示例8: storeMessage

import java.time.Instant; //導入依賴的package包/類
/**
 * Stores a new secure message and return the senderId.
 */
public String storeMessage(final String message, final List<SecretFile> files,
                           final KeyIv encryptionKey,
                           final byte[] linkSecret,
                           final String password,
                           final Instant expiration) {

    final boolean isMessagePasswordProtected = password != null;

    final String senderId = newRandomId();

    final String receiverId = storeMessage(
        senderId, message, encryptionKey, files,
        linkSecret, password, expiration);

    saveSenderMessage(senderId,
        new SenderMessage(senderId, receiverId, isMessagePasswordProtected, expiration));

    return senderId;
}
 
開發者ID:osiegmar,項目名稱:setra,代碼行數:23,代碼來源:MessageSenderService.java

示例9: chronoRangeCompareTest10

import java.time.Instant; //導入依賴的package包/類
@Test
public void chronoRangeCompareTest10() {
    ChronoSeries chronoSeries = ChronoSeries.of(
            Instant.parse("2017-02-28T08:48:11Z"),
            Instant.parse("2017-02-28T08:48:12Z"),
            Instant.parse("2017-02-28T08:48:13Z"),
            Instant.parse("2017-02-28T08:48:14Z"),
            Instant.parse("2017-02-28T08:48:15Z")
    );
    ISeq<ChronoGene> genes = ISeq.of(
            new ChronoGene(new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.SECONDS), 0, 10)),
            new ChronoGene(new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.SECONDS), 0, 11))
    );
    ChronoRange chronoRange = ChronoRange.getChronoRange(chronoSeries, genes);

    genes = ISeq.of(
            new ChronoGene(new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.SECONDS), 0, 11)),
            new ChronoGene(new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.SECONDS), 0, 10))
    );
    ChronoRange chronoRange2 = ChronoRange.getChronoRange(chronoSeries, genes);

    assertTrue(chronoRange.isSameChronoRange(chronoRange2));
}
 
開發者ID:BFergerson,項目名稱:Chronetic,代碼行數:24,代碼來源:ChronoRangeTest.java

示例10: testResourcePast

import java.time.Instant; //導入依賴的package包/類
@Test
public void testResourcePast() {
    final Instant time = parse("2017-02-15T11:00:00Z");
    final Resource res = VersionedResource.find(file, identifier, time).get();
    assertEquals(identifier, res.getIdentifier());
    assertFalse(res.hasAcl());
    assertEquals(LDP.Container, res.getInteractionModel());
    assertFalse(res.getMembershipResource().isPresent());
    assertFalse(res.getMemberRelation().isPresent());
    assertFalse(res.getMemberOfRelation().isPresent());
    assertFalse(res.getInsertedContentRelation().isPresent());
    assertFalse(res.getBinary().isPresent());
    assertTrue(res.isMemento());
    assertFalse(res.getInbox().isPresent());
    assertEquals(parse("2017-02-15T10:05:00Z"), res.getModified());
    assertEquals(0L, res.getTypes().size());
    assertEquals(0L, res.stream().filter(TestUtils.isContainment.or(TestUtils.isMembership)).count());

    final List<Triple> triples = res.stream().filter(TestUtils.isUserManaged).map(Quad::asTriple).collect(toList());
    assertEquals(0L, triples.size());

    final List<VersionRange> mementos = res.getMementos();
    assertEquals(1L, mementos.size());
    assertEquals(parse("2017-02-15T10:05:00Z"), mementos.get(0).getFrom());
    assertEquals(parse("2017-02-15T11:15:00Z"), mementos.get(0).getUntil());
}
 
開發者ID:trellis-ldp-archive,項目名稱:trellis-rosid-file,代碼行數:27,代碼來源:LdpContainerTest.java

示例11: buildGoLiveEmbed

import java.time.Instant; //導入依賴的package包/類
public static MessageEmbed buildGoLiveEmbed(BTBBeamChannel channel) {
	return new EmbedBuilder()
			.setTitle(String.format("%s is now live!", channel.user.username),
					String.format("https://beam.pro/%s", channel.user.username))
			.setThumbnail(String.format("https://beam.pro/api/v1/users/%d/avatar?_=%d", channel.user.id,
					new Random().nextInt()))
			.setDescription(StringUtils.isBlank(channel.user.bio) ? "No bio" : channel.user.bio)
			.addField(channel.name, channel.type == null ? "No game selected" : channel.type.name, false)
			.addField("Followers", Integer.toString(channel.numFollowers), true)
			.addField("Views", Integer.toString(channel.viewersTotal), true)
			.addField("Rating", Enums.serializedName(channel.audience), true)
			.setImage(String.format("https://thumbs.beam.pro/channel/%d.small.jpg?_=%d", channel.id,
					new Random().nextInt()))
			.setFooter("Beam.pro", CommandHelper.BEAM_LOGO_URL).setTimestamp(Instant.now())
			.setColor(CommandHelper.COLOR).build();
}
 
開發者ID:StreamerSpectrum,項目名稱:BeamTeamDiscordBot,代碼行數:17,代碼來源:JDAManager.java

示例12: getLocalImageTimestamp

import java.time.Instant; //導入依賴的package包/類
private static Instant getLocalImageTimestamp(String imageName) {
	// Use docker inspect
	try {
		String isoDatetime = DefaultCommandRunner.INSTANCE.runCommandAndCaptureOutput("docker", "inspect", "-f", "{{.Created}}", imageName);
		return Instant.from(DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(isoDatetime));
	}
	catch (RuntimeException e) {
		log.debug("Could not determine timestamp of local image [" + imageName + "], assuming it doesn't exist on the local docker host", e);
		return null;
	}
}
 
開發者ID:swissquote,項目名稱:carnotzet,代碼行數:12,代碼來源:DockerRegistry.java

示例13: toTableRow

import java.time.Instant; //導入依賴的package包/類
public TableRow toTableRow() {
  TableRow result = new TableRow();
  result.set("latitude", lat);
  result.set("longitude", lon);
  result.set("ride_id", rideId);
  result.set("timestamp", Instant.ofEpochMilli(timestamp).toString());
  result.set("ride_status", status);
  return result;
}
 
開發者ID:googlecodelabs,項目名稱:cloud-dataflow-nyc-taxi-tycoon,代碼行數:10,代碼來源:RidePoint.java

示例14: enqueue

import java.time.Instant; //導入依賴的package包/類
private synchronized void enqueue(Map<String, String> entry) {
    if (queue.size() > QUEUE_MAX_SIZE) {
        queue.poll();
    }
    if (entry != null) {
        entry.put(TIMESTAMP_NAME, Instant.now().toString());
        queue.add(entry);
    }
}
 
開發者ID:Microsoft,項目名稱:java-debug,代碼行數:10,代碼來源:UsageDataStore.java

示例15: onGuildVoiceMute

import java.time.Instant; //導入依賴的package包/類
@Override
public final void onGuildVoiceMute(GuildVoiceMuteEvent event) {
    if (!LOG_MUTES) {
        return;
    }
    Standard.log(Instant.now(), event.getGuild(), LOG_NAME, LOG_CHANNEL_ID_VOICE, LOG_TEXT_VOICE_MUTE, "[%1$s] [%2$s] %3$s was %4$s", LOG_DATE_TIME_FORMAT, Config.CONFIG.getUserNameForUser(event.getMember().getUser(), event.getGuild(), true), (event.isMuted() ? "muted" : "unmuted"));
}
 
開發者ID:Panzer1119,項目名稱:Supreme-Bot,代碼行數:8,代碼來源:GuildVoiceLogger.java


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