本文整理汇总了Java中java.time.ZonedDateTime.format方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.format方法的具体用法?Java ZonedDateTime.format怎么用?Java ZonedDateTime.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.format方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServerTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private HelloResponseServertime getServerTime() {
final ZonedDateTime now = ZonedDateTime.now();
final String dateFormatted = now.format(DateTimeFormatter.ISO_INSTANT);
final HelloResponseServertime serverTime = new HelloResponseServertime();
serverTime.timestamp(new Date().getTime());
serverTime.iso8601(dateFormatted);
return serverTime;
}
示例2: 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();
}
示例3: sut_serializes_ZonedDateTime_as_iso_8601
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void sut_serializes_ZonedDateTime_as_iso_8601() {
// Arrange
ZonedDateTime dateTime = ZonedDateTime.now(Clock.systemUTC());
MessageWithZonedDateTimeProperty message = new MessageWithZonedDateTimeProperty(dateTime);
JacksonMessageSerializer sut = new JacksonMessageSerializer();
// Act
String actual = sut.serialize(message);
System.out.println("The serialized value is '" + actual + "'.");
// Assert
String formatted = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);
Assert.assertTrue(actual.contains("\"dateTime\":\"" + formatted + "\""));
}
示例4: vanZonedDateTimeNaarXsdDateTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* @param zonedDateTime zonedDateTime
* @return xsd datetime
*/
public static String vanZonedDateTimeNaarXsdDateTime(final ZonedDateTime zonedDateTime) {
if (zonedDateTime == null) {
return null;
}
return zonedDateTime.format(DATE_TIME_FORMATTER);
}
示例5: Credentials
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public Credentials(final BasicSessionCredentials credentials,
final ZonedDateTime expiration) {
this.accessKeyId = credentials.getAWSAccessKeyId();
this.secretAccessKey = credentials.getAWSSecretKey();
this.sessionToken = credentials.getSessionToken();
this.expiration = expiration.format(DateTimeFormatter.ISO_INSTANT);
}
示例6: zonedDateTimeCompatibilityWithDateTimeFormatter
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void zonedDateTimeCompatibilityWithDateTimeFormatter() throws Exception {
final ZonedDateTime out = ZonedDateTime.now();
final String s = out.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
final ZonedDateTime in = VPackJdk8Deserializers.ZONED_DATE_TIME.deserialize(null,
new VPackBuilder().add(s).slice(), null);
assertThat(in, is(out));
}
示例7: getDateRangeFor
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private static String getDateRangeFor(ZonedDateTime dateTime){
String day = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String range= String.format("%sT00:00:00.000Z,%sT23:59:59.000Z", day, day);
return range;
}
示例8: convert
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public String convert(ZonedDateTime source) {
return source.format(FORMATTER);
}
示例9: toFileSaveFormat
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static String toFileSaveFormat(@Nonnull ZonedDateTime zdt) {
return zdt.format(fileSaveFormat);
}
示例10: getFormatDate
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public String getFormatDate(ZonedDateTime dateTime) {
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return dateTime.format(format);
}
示例11: serialize
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public JsonElement serialize(ZonedDateTime date, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(date.format(DateTimeFormatter.ISO_DATE_TIME));
}
示例12: nowUTC
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static String nowUTC() {
ZonedDateTime localNow = ZonedDateTime.now();
ZonedDateTime utcNow = localNow.withZoneSameInstant(utc);
return utcNow.format(comparableFormatter);
}
示例13: from
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static String from(ZonedDateTime timestamp) {
return timestamp.format(comparableFormatter);
}
示例14: toHumanReadable
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static String toHumanReadable(ZonedDateTime timestamp) {
return timestamp.format(humanReadableFormatter);
}