当前位置: 首页 > 工具软件 > parse5 > 使用案例 >

java的parse方法_Java即时类| parse()方法与示例

阎彬炳
2023-12-01

java的parse方法

即时类parse()方法 (Instant Class parse() method)

  • parse() method is available in java.time package.

    parse()方法在java.time包中可用。

  • parse() method is used to get an Instant that parses the given char sequence and char sequence follow some standard format like 2007-12-03T10:15:30.00Z.

    parse()方法用于获取一个Instant,该Instant解析给定的char序列,并且char序列遵循某些标准格式,例如2007-12-03T10:15:30.00Z。

  • parse() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    parse()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出错。

  • parse() method may throw an exception at the time of parsing the given sequence.

    parse()方法在解析给定序列时可能会引发异常。

    DateTimeParseException: This exception may throw when the given parameter couldn't parse.

    DateTimeParseException :如果无法解析给定参数,则可能引发此异常。

Syntax:

句法:

    public static Instant parse(CharSequence cs);

Parameter(s):

参数:

  • CharSequence cs – represents the char sequence to parse to a Instant.

    CharSequence cs –表示要解析为Instant的char序列。

Return value:

返回值:

The return type of this method is Instant, it returns the Instant that holds the parse value of the given sequence to an Instant.

此方法的返回类型为Instant ,它将将持有给定序列的解析值的Instant返回给Instant。

Example:

例:

// Java program to demonstrate the example 
// of parse(CharSequence cs) method 
// of Instant

import java.time.*;

public class ParseOfInstant {
    public static void main(String args[]) {
        CharSequence c_seq = "2006-04-04T10:30:30.60Z";

        // Here, this method creates an Instant 
        // from a parse CharSequence
        Instant ins = Instant.parse(c_seq);

        // Display ins
        System.out.println("Instant.parse(c_seq): " + ins);


        // Here, this method creates an Instant
        // from a parse string
        ins = Instant.parse("2008-01-01T10:10:10.00Z");

        // Display ins
        System.out.println("Instant.parse(2008-01-01T10:10:10.00Z): " + ins);
    }
}

Output

输出量

Instant.parse(c_seq): 2006-04-04T10:30:30.600Z
Instant.parse(2008-01-01T10:10:10.00Z): 2008-01-01T10:10:10Z

翻译自: https://www.includehelp.com/java/instant-parse-method-with-example.aspx

java的parse方法

 类似资料: