本文整理了Java中java.time.OffsetDateTime.format()
方法的一些代码示例,展示了OffsetDateTime.format()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.format()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:format
[英]Outputs this date-time as a String using the formatter.
This date-time will be passed to the formatter DateTimeFormatter#format(TemporalAccessor).
[中]使用格式化程序将此日期时间作为字符串输出。
此日期时间将传递给格式化程序DateTimeFormatter#format(TemporalAccessor)。
代码示例来源:origin: codecentric/spring-boot-admin
@Override
public Map<String, String> getMetadata() {
return singletonMap("startup", this.timestamp.format(DateTimeFormatter.ISO_DATE_TIME));
}
}
代码示例来源:origin: stackoverflow.com
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss,nnnnnnnnnZ");
OffsetDateTime odt = OffsetDateTime.of(2015, 11, 2, 12, 38, 0, 123456789, ZoneOffset.UTC);
System.out.println(odt.format(formatter));
代码示例来源:origin: prontera/spring-cloud-rest-tcc
@Override
public void serialize(OffsetDateTime dateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeString(dateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
}
}
代码示例来源:origin: confluentinc/ksql
public String timestamp() {
if (timestamp == 0) {
return "n/a";
}
return Instant.ofEpochMilli(timestamp)
.atOffset(ZoneOffset.UTC)
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public String getStartTimeLocal() {
return statMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public String format(final LogRecord record) {
OffsetDateTime date = fromMillis(record.getMillis());
StringBuilder sb = new StringBuilder();
// Minimize memory allocations here.
sb.append("[").append(Thread.currentThread().getName()).append("] ");
sb.append(date.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)).append(" ");
sb.append(record.getLevel()).append(" [");
sb.append(record.getLoggerName()).append("]").append(" ");
sb.append(record.getMessage());
sb.append(Utils.LINE_SEPARATOR);
if (record.getThrown() != null) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
record.getThrown().printStackTrace(pw);
pw.close();
sb.append(sw.toString());
} catch (Exception ex) {
ex.printStackTrace();
}
}
return sb.toString();
}
代码示例来源:origin: debezium/debezium
/**
* Get the ISO 8601 formatted representation of the given {@link OffsetDateTime}.
*
* @param timestamp the timestamp value
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
* @return the ISO 8601 formatted string
*/
public static String toIsoString(OffsetDateTime timestamp, TemporalAdjuster adjuster) {
if (adjuster != null) {
timestamp = timestamp.with(adjuster);
}
return timestamp.format(FORMATTER);
}
代码示例来源:origin: kiegroup/optaplanner
public String getStartingTimestampAsMediumString() {
return startingTimestamp == null ? null : startingTimestamp.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
}
代码示例来源:origin: kiegroup/jbpm
public static String[] parseISORepeatable(String isoString) {
String[] result = new String[3];
String[] elements = isoString.split("/");
if (elements.length==3) {
result[0] = elements[0].substring(1);
result[1] = elements[1];
result[2] = elements[2];
} else {
result[0] = elements[0].substring(1);
result[1] = OffsetDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME);
result[2] = elements[1];
}
return result;
}
代码示例来源:origin: kiegroup/optaplanner
public void initBenchmarkReportDirectory(File benchmarkDirectory) {
String timestampString = startingTimestamp.format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HHmmss"));
if (StringUtils.isEmpty(name)) {
name = timestampString;
}
if (!benchmarkDirectory.mkdirs()) {
if (!benchmarkDirectory.isDirectory()) {
throw new IllegalArgumentException("The benchmarkDirectory (" + benchmarkDirectory
+ ") already exists, but is not a directory.");
}
if (!benchmarkDirectory.canWrite()) {
throw new IllegalArgumentException("The benchmarkDirectory (" + benchmarkDirectory
+ ") already exists, but is not writable.");
}
}
int duplicationIndex = 0;
do {
String directoryName = timestampString + (duplicationIndex == 0 ? "" : "_" + duplicationIndex);
duplicationIndex++;
benchmarkReportDirectory = new File(benchmarkDirectory,
BooleanUtils.isFalse(aggregation) ? directoryName : directoryName + "_aggregation");
} while (!benchmarkReportDirectory.mkdir());
for (ProblemBenchmarkResult problemBenchmarkResult : unifiedProblemBenchmarkResultList) {
problemBenchmarkResult.makeDirs();
}
}
代码示例来源:origin: apache/drill
/**
* Applies local time zone offset to timestamp value read using specified {@code reader}.
*
* @param writer writer to store string representation of timestamp value
* @param fieldName name of the field
* @param reader document reader
*/
@Override
protected void writeTimeStamp(MapOrListWriterImpl writer, String fieldName, DocumentReader reader) {
String formattedTimestamp = Instant.ofEpochMilli(reader.getTimestampLong())
.atOffset(OffsetDateTime.now().getOffset()).format(DateUtility.UTC_FORMATTER);
writeString(writer, fieldName, formattedTimestamp);
}
};
代码示例来源:origin: spring-projects/spring-session
: Instant.EPOCH.atOffset(ZoneOffset.UTC);
sb.append("; Expires=")
.append(expires.format(DateTimeFormatter.RFC_1123_DATE_TIME));
代码示例来源:origin: kiegroup/jbpm
@Test
public void testParseDateTime() {
OffsetDateTime hourAfterEpoch = OffsetDateTime.of(1970, 1, 1, 1, 0, 0, 0, ZoneOffset.UTC);
long parsedMilliseconds = DateTimeUtils.parseDateTime(hourAfterEpoch.format(DateTimeFormatter.ISO_DATE_TIME));
assertEquals(HOUR_IN_MILLISECONDS, parsedMilliseconds);
}
代码示例来源:origin: DV8FromTheWorld/JDA
/**
* Returns a prettier String-representation of a OffsetDateTime object
*
* @param time
* The OffsetDateTime object to format
*
* @return The String of the formatted OffsetDateTime
*/
public static String getDateTimeString(OffsetDateTime time)
{
return time.format(dtFormatter);
}
代码示例来源:origin: apache/ignite
/**
* Simple test JMX bean for caches IO stats.
*
* @throws Exception In case of failure.
*/
@Test
public void testCacheBasic() throws Exception {
IoStatisticsMetricsMXBean bean = ioStatMXBean();
IoStatisticsManager ioStatMgr = ignite.context().ioStats();
Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime());
Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal());
bean.reset();
Assert.assertEquals(ioStatMgr.startTime().toEpochSecond(), bean.getStartTime());
Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal());
int cnt = 100;
warmUpMemmory(bean, cnt);
populateCache(cnt);
Long cacheLogicalReadsCnt = bean.getCacheGroupLogicalReads(DEFAULT_CACHE_NAME);
Assert.assertNotNull(cacheLogicalReadsCnt);
Assert.assertEquals(cnt, cacheLogicalReadsCnt.longValue());
Long cachePhysicalReadsCnt = bean.getCacheGroupPhysicalReads(DEFAULT_CACHE_NAME);
Assert.assertNotNull(cachePhysicalReadsCnt);
Assert.assertEquals(0, cachePhysicalReadsCnt.longValue());
String formatted = bean.getCacheGroupStatistics(DEFAULT_CACHE_NAME);
Assert.assertEquals("CACHE_GROUP default [LOGICAL_READS=100, PHYSICAL_READS=0]", formatted);
String unexistedStats = bean.getCacheGroupStatistics("unknownCache");
Assert.assertEquals("CACHE_GROUP unknownCache []", unexistedStats);
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testParseRepeatableStartEndDateTime() {
OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1);
OffsetDateTime twoMinutesFromNow = oneMinuteFromNow.plusMinutes(1);
String oneMinuteFromNowFormatted = oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
String twoMinutesFromNowFormatted = twoMinutesFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
String isoString = "R5/" + oneMinuteFromNowFormatted + "/" + twoMinutesFromNowFormatted;
long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString);
assertEquals(5L, parsedRepeatable[0]);
assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS);
assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]);
}
代码示例来源:origin: apache/ignite
Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal());
Assert.assertEquals(ioStatMgr.startTime().format(DateTimeFormatter.ISO_DATE_TIME), bean.getStartTimeLocal());
代码示例来源:origin: kiegroup/jbpm
@Test
public void testParseDateAsDuration() {
OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1);
long parsedMilliseconds = DateTimeUtils.parseDateAsDuration(oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME));
assertTrue("Parsed date as duration is bigger than " + MINUTE_IN_MILLISECONDS, parsedMilliseconds <= MINUTE_IN_MILLISECONDS);
assertTrue("Parsed date as duration is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedMilliseconds, parsedMilliseconds > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testParseRepeatablePeriodAndEndDateTime() {
OffsetDateTime twoMinutesFromNow = OffsetDateTime.now().plusMinutes(2);
String twoMinutesFromNowFormatted = twoMinutesFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
String isoString = "R5/PT1M/" + twoMinutesFromNowFormatted;
long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString);
assertEquals(5L, parsedRepeatable[0]);
assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS);
assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]);
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testParseRepeatableStartDateTimeAndPeriod() {
OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1);
String oneMinuteFromNowFormatted = oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
String isoString = "R5/" + oneMinuteFromNowFormatted + "/PT1M";
long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString);
assertEquals(5L, parsedRepeatable[0]);
assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS);
assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]);
}
内容来源于网络,如有侵权,请联系作者删除!