本文整理汇总了Java中java.time.ZonedDateTime.from方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.from方法的具体用法?Java ZonedDateTime.from怎么用?Java ZonedDateTime.from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS]").withZone(ZoneId.of("UTC"));
String value = p.getValueAsString();
ZonedDateTime result = null;
if(value != null) {
int index;
if ((index = value.indexOf('.')) > -1) {
char[] chars = new char[4 - (value.length() - index)];
Arrays.fill(chars, '0');
value += new String(chars);
}
result = ZonedDateTime.from(formatter.parse(value));
}
return result;
}
示例2: ZonedDateTimeOf
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Parses the date using the formatter to create
* {@link ZonedDateTime} instances.
* @param date The date to parse.
* @param formatter The formatter to use.
*/
public ZonedDateTimeOf(final CharSequence date,
final DateTimeFormatter formatter) {
this.parsed = new UncheckedScalar<>(
() -> ZonedDateTime.from(formatter.parse(date))
);
}
示例3: parseWaarde
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Maakt een DatumElement obv de gegeven string.
*
* @param waarde de waarde, mag niet null zijn
* @return DatumElement
* @throws OngeldigeWaardeException wanneer er geen de gegeven string een ongeldige waarde bevat
*/
public static DatumTijdElement parseWaarde(final String waarde) throws OngeldigeWaardeException {
ValidatieHelper.controleerOpNullWaarde(waarde, "waarde");
try {
return new DatumTijdElement(ZonedDateTime.from(DATUM_TIJD_FORMATTER.parse(waarde)));
} catch (DateTimeException e) {
throw new OngeldigeWaardeException(String.format(FOUTMELDING, waarde), e);
}
}
示例4: parseTest
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void parseTest() throws IOException{
ObjectMapper mapper = new ObjectMapper();
Instant now = Instant.ofEpochSecond(System.currentTimeMillis() / 1000);
ZonedDateTime auth_time = ZonedDateTime.ofInstant(now, ZoneId.systemDefault());
ZonedDateTime iat = ZonedDateTime.from(auth_time);
ZonedDateTime exp = ZonedDateTime
.ofInstant(now, ZoneId.systemDefault())
.plusMinutes(30);
ZonedDateTime nbf = exp.minusMinutes(1);
String jsonToken = "{\n" + " \"exp\": " + exp.toEpochSecond() + ",\n" + " \"nbf\": " + nbf.toEpochSecond() + ",\n" + " \"ver\": \"1.0\",\n" + " \"iss\": \"https://login.microsoftonline.com/11111111-1111-1111-1111-111111111111/v2.0/\",\n" + " \"acr\": \"b2c_1_what-you-named-the-policy\",\n" + " \"sub\": \"Not supported currently. Use oid claim.\",\n" + " \"aud\": \"11111111-1111-1111-1111-111111111111\",\n" + " \"nonce\": \"11111111-1111-1111-1111-111111111111\",\n" + " \"iat\": " + iat.toEpochSecond() + ",\n" + " \"auth_time\": " + auth_time.toEpochSecond() + ",\n" + " \"oid\": \"11111111-1111-1111-1111-111111111111\",\n" + " \"given_name\": \"One Punch\",\n" + " \"family_name\": \"Saitama\",\n" + " \"emails\": [\n" + " \"[email protected]\"\n" + " ]\n" + "}";
BlueWebToken token = mapper.readValue(jsonToken, BlueWebToken.class);
assertEquals(token.getExpiration(), exp);
assertEquals(token.getNotBefore(), nbf);
assertEquals(token.getVersion(), "1.0");
assertEquals(token.getIssuer(), "https://login.microsoftonline.com/11111111-1111-1111-1111-111111111111/v2.0/");
assertEquals(token.getAuthContextReference(), "b2c_1_what-you-named-the-policy");
assertEquals(token.getSubject(), "Not supported currently. Use oid claim.");
assertEquals(token.getAudience(), "11111111-1111-1111-1111-111111111111");
assertEquals(token.getNonce(), "11111111-1111-1111-1111-111111111111");
assertEquals(token.getIssuedAt(), iat);
assertEquals(token.getAuthTime(), auth_time);
assertEquals(token.getObjectId(), "11111111-1111-1111-1111-111111111111");
assertEquals(token.getFirstName(), "One Punch");
assertEquals(token.getLastName(), "Saitama");
assertEquals(token.getFirstEmail(), "[email protected]");
}
示例5: getExpirationDate
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* @return the expirationDate
*/
public ZonedDateTime getExpirationDate() {
return this.expirationDate == null ? null : ZonedDateTime.from(this.expirationDate);
}
示例6: getExpirationDate
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* @return Returns the expirationDate.
*/
public ZonedDateTime getExpirationDate() {
return this.expirationDate == null ? null : ZonedDateTime.from(this.expirationDate);
}
示例7: factory_from_TemporalAccessor_invalid_noDerive
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_from_TemporalAccessor_invalid_noDerive() {
ZonedDateTime.from(LocalTime.of(12, 30));
}
示例8: factory_from_TemporalAccessor_null
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_from_TemporalAccessor_null() {
ZonedDateTime.from((TemporalAccessor) null);
}
示例9: test_parse_instantNoZone_ZDT
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider = "instantNoZone", expectedExceptions = DateTimeException.class)
public void test_parse_instantNoZone_ZDT(DateTimeFormatter formatter, String text, Instant expected) {
TemporalAccessor actual = formatter.parse(text);
ZonedDateTime.from(actual);
}
示例10: ExpiredCRLException
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Creates a new instance describing a CRL that expired on a date that is
* more than leniency seconds beyond its expiration date.
*
* @param identifier Identifier or name that describes CRL.
* @param expirationDate CRL expiration date.
* @param leniency Number of seconds beyond the expiration date at which
* the CRL is considered expired. MUST be non-negative integer.
*/
public ExpiredCRLException(final String identifier, final ZonedDateTime expirationDate, final int leniency) {
this.id = identifier;
this.expirationDate = ZonedDateTime.from(expirationDate);
if (leniency < 0) {
throw new IllegalArgumentException("Leniency must not be negative.");
}
this.leniency = leniency;
}
示例11: zonedDateTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Obtains an ISO zoned date-time from another date-time object.
* <p>
* This is equivalent to {@link ZonedDateTime#from(DateTimeAccessor)}.
*
* @param dateTime the date-time object to convert, not null
* @return the ISO zoned date-time, not null
* @throws DateTimeException if unable to create the date-time
*/
@Override
// override with covariant return type
public ZonedDateTime zonedDateTime(DateTimeAccessor dateTime) {
return ZonedDateTime.from(dateTime);
}
示例12: RevokedCertificateException
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Instantiates a new revoked certificate exception.
*
* @param revoked the revoked
* @param serial the serial
* @param reason the reason
*/
public RevokedCertificateException(final ZonedDateTime revoked, final BigInteger serial, final Reason reason) {
this.revocationDate = ZonedDateTime.from(revoked);
this.serial = serial;
this.reason = reason;
}
示例13: getRevocationDate
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Gets the revocation date.
*
* @return Returns the revocationDate.
*/
public ZonedDateTime getRevocationDate() {
return this.revocationDate == null ? null : ZonedDateTime.from(this.revocationDate);
}
示例14: zonedDateTimeOf
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Utility for creating a ZonedDateTime object from a ZonedDateTime.
*
* @param time ZonedDateTime to be copied
* @return ZonedDateTime representing time
*/
public static ZonedDateTime zonedDateTimeOf(final ZonedDateTime time) {
return ZonedDateTime.from(time);
}
示例15: zonedDateTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* Obtains an ISO zoned date-time from another date-time object.
* <p>
* This is equivalent to {@link ZonedDateTime#from(TemporalAccessor)}.
*
* @param temporal the date-time object to convert, not null
* @return the ISO zoned date-time, not null
* @throws DateTimeException if unable to create the date-time
*/
@Override // override with covariant return type
public ZonedDateTime zonedDateTime(TemporalAccessor temporal) {
return ZonedDateTime.from(temporal);
}