Java Data Type How to - Create Instant from '2010-01-01T12:00:00Z'








Question

We would like to know how to create Instant from '2010-01-01T12:00:00Z'.

Answer

// w ww  .ja va 2s . c o m
import java.time.Instant;

public class Main {
  public static void main(String[] args) {

    // parsing from ISO 8601
    Instant fromIso8601 = Instant.parse("2010-01-01T12:00:00Z");
    
    System.out.println(fromIso8601);
  }
}

The code above generates the following result.