当前位置: 首页>>代码示例>>Java>>正文


Java ZonedDateTime.from方法代码示例

本文整理汇总了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;
}
 
开发者ID:CCob,项目名称:bittrex4j,代码行数:22,代码来源:DateTimeDeserializer.java

示例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))
    );
}
 
开发者ID:yegor256,项目名称:cactoos,代码行数:13,代码来源:ZonedDateTimeOf.java

示例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);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:16,代码来源:DatumTijdElement.java

示例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]");
}
 
开发者ID:Xitikit,项目名称:xitikit-blue,代码行数:30,代码来源:BlueWebTokenTest.java

示例5: getExpirationDate

import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
 * @return the expirationDate
 */
public ZonedDateTime getExpirationDate() {
    return this.expirationDate == null ? null : ZonedDateTime.from(this.expirationDate);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:7,代码来源:JpaLockingStrategy.java

示例6: getExpirationDate

import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
 * @return Returns the expirationDate.
 */
public ZonedDateTime getExpirationDate() {
    return this.expirationDate == null ? null : ZonedDateTime.from(this.expirationDate);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:7,代码来源:ExpiredCRLException.java

示例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));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKZonedDateTime.java

示例8: factory_from_TemporalAccessor_null

import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_from_TemporalAccessor_null() {
    ZonedDateTime.from((TemporalAccessor) null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKZonedDateTime.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TestDateTimeParsing.java

示例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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:ExpiredCRLException.java

示例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);
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:16,代码来源:ISOChrono.java

示例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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:13,代码来源:RevokedCertificateException.java

示例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);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:9,代码来源:RevokedCertificateException.java

示例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);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:11,代码来源:DateTimeUtils.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:IsoChronology.java


注:本文中的java.time.ZonedDateTime.from方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。