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 Instantimport 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 CharSequenceInstant ins = Instant.parse(c_seq);// Display insSystem.out.println("Instant.parse(c_seq): " + ins);// Here, this method creates an Instant// from a parse stringins = Instant.parse("2008-01-01T10:10:10.00Z");// Display insSystem.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方法
總結
以上是生活随笔為你收集整理的java的parse方法_Java即时类| parse()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言1+2+3+4+5_C程序来计算系
- 下一篇: Python | 基于参数和返回值的功能