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

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方法

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值