OffsetTime parse() method in Java with examples Last Updated : 31 Dec, 2018 Comments Improve Suggest changes Like Article Like Report In OffsetTime class, there are two types of parse() method depending upon the parameters passed to it. parse(CharSequence text) parse() method of a OffsetTime class used to get an instance of OffsetTime from a string such as '15:25:10+01:00' passed as parameter.The string must have a valid date-time and is parsed using DateTimeFormatter.ISO_LOCAL_TIME. Syntax: public static OffsetTime parse(CharSequence text) Parameters: This method accepts only one parameter text which is the text to parse in OffsetTime. It should not be null. Return value: This method returns OffsetTime which is the parsed local date-time. Exception: This method throws DateTimeParseException if the text cannot be parsed. Below programs illustrate the parse() method: Program 1: Java // Java program to demonstrate // OffsetTime.parse() method import java.time.*; public class GFG { public static void main(String[] args) { // create an OffsetTime object OffsetTime lt = OffsetTime.parse("15:25:10+01:00"); // print result System.out.println("OffsetTime : " + lt); } } Output: OffsetTime : 15:25:10+01:00 parse(CharSequence text, DateTimeFormatter formatter) parse() method of a OffsetTime class used to get an instance of OffsetTime from a string such as '15:25:10+01:00' passed as parameter using a specific formatter.The date-time is parsed using a specific formatter. Syntax: public static OffsetTime parse(CharSequence text, DateTimeFormatter formatter) Parameters: This method accepts two parameters text which is the text to parse and formatter which is the formatter to use. Return value: This method returns OffsetTime which is the parsed local date-time. Exception: This method throws DateTimeParseException if the text cannot be parsed. Below programs illustrate the parse() method: Program 1: Java // Java program to demonstrate // OffsetTime.parse() method import java.time.*; import java.time.format.DateTimeFormatter; public class GFG { public static void main(String[] args) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_TIME; // create an OffsetTime object and OffsetTime lt = OffsetTime .parse("11:35:34+01:00", dateTimeFormatter); // print result System.out.println("OffsetTime : " + lt); } } Output: OffsetTime : 11:35:34+01:00 References: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#parse-java.lang.CharSequence- Comment More infoAdvertise with us Next Article OffsetTime parse() method in Java with examples G gopaldave Follow Improve Article Tags : Java Java-Functions Java-time package Java-OffsetTime Practice Tags : Java Similar Reads OffsetTime query() method in Java with examples The Query() method of OffsetTime class in Java queries this time using the specified query. Syntax : public R query(TemporalQuery query) Parameter: This method accepts a single parameter query that specifies the query to be invoked and not null. Return Value: It returns the query result, null may be 1 min read OffsetTime of() method in Java with Examples The of(int hour, int minute, int second, int nanosecond, ZoneOffset offset) method of the OffsetTime class in Java is used to create an instance of OffsetTime from the passed values of hour, minute, second and nanosecond. In this method, we pass the value of hour, minute, second and nanosecond in in 2 min read OffsetDateTime plusYears() method in Java with examples The plusYears() method of OffsetDateTime class in Java returns a copy of this OffsetDateTime with the specified number of years added to the parsed date and time. Syntax: public OffsetDateTime plusYears(long years) Parameter: This method accepts a single parameter years which specifies the years to 2 min read OffsetTime get() method in Java with examples The get() method of OffsetTime class in Java gets the value of the specified field from this time as an int. Syntax : public int get(TemporalField field) Parameter : This method accepts a parameter field which specifies the field to get, not null.Return Value: It returns the value for the field.Exce 2 min read OffsetTime until() Method in Java with Examples until() method of the OffsetTime class used to calculate the amount of time between two OffsetTime objects using TemporalUnit. The start and end points are this and the specified OffsetTime passed as a parameter. The result will be negative if the end is before the start. The calculation returns a w 2 min read Like