Example usage for java.time.temporal TemporalAccessor getClass

List of usage examples for java.time.temporal TemporalAccessor getClass

Introduction

In this page you can find the example usage for java.time.temporal TemporalAccessor getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.dv8tion.jda.core.EmbedBuilder.java

/**
 * Sets the Timestamp of the embed.// www.  j a v  a2  s . c om
 *
 * <p><b><a href="http://i.imgur.com/YP4NiER.png">Example</a></b>
 *
 * <p><b>Hint:</b> You can get the current time using {@link java.time.Instant#now() Instant.now()} or convert time from a
 * millisecond representation by using {@link java.time.Instant#ofEpochMilli(long) Instant.ofEpochMilli(long)};
 *
 * @param  temporal
 *         the temporal accessor of the timestamp
 *
 * @return the builder after the timestamp has been set
 */
public EmbedBuilder setTimestamp(TemporalAccessor temporal) {
    if (temporal == null) {
        this.timestamp = null;
    } else if (temporal instanceof OffsetDateTime) {
        this.timestamp = (OffsetDateTime) temporal;
    } else {
        ZoneOffset offset;
        try {
            offset = ZoneOffset.from(temporal);
        } catch (DateTimeException ignore) {
            offset = ZoneOffset.UTC;
        }
        try {
            LocalDateTime ldt = LocalDateTime.from(temporal);
            this.timestamp = OffsetDateTime.of(ldt, offset);
        } catch (DateTimeException ignore) {
            try {
                Instant instant = Instant.from(temporal);
                this.timestamp = OffsetDateTime.ofInstant(instant, offset);
            } catch (DateTimeException ex) {
                throw new DateTimeException("Unable to obtain OffsetDateTime from TemporalAccessor: " + temporal
                        + " of type " + temporal.getClass().getName(), ex);
            }
        }
    }
    return this;
}