Java Date Time - OffsetDateTime getLong(TemporalField field) example








OffsetDateTime getLong(TemporalField field) gets the value of the specified field from this date-time as a long.

Syntax

getLong has the following syntax.

public long getLong(TemporalField field)

Example

The following example shows how to use getLong.

import java.time.OffsetDateTime;
import java.time.temporal.ChronoField;
//from   w  ww .ja v a  2  s  .  c o  m
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    long l = o.getLong(ChronoField.DAY_OF_WEEK);
    System.out.println(l);
  }
}

The code above generates the following result.