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.


getLong has the following syntax.

public long getLong(TemporalField field)


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 =;
    long l = o.getLong(ChronoField.DAY_OF_WEEK);

The code above generates the following result.