java中get接口示例

LocalDateTime类的get()方法 (LocalDateTime Class get() method)

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

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

  • get() method is used to get the value for the given field from this date-time object.

    get()方法用于从此日期时间对象获取给定字段的值。

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

    get()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • get() method may throw an exception at the time of returning value for the given field.

    在返回给定字段的值时, get()方法可能会引发异常。

    • DateTimeException – This exception may throw when the given field couldn’t be generated.
    • UnsupportedTemporalTypeException – This exception may throw when the given field is unsupported.
    • ArithmeticException – This exception may throw when the calculated result exceeds the limit.

Syntax:

句法:

    public int get(TemporalField t_field);

Parameter(s):

参数:

  • TemporalField t_field – represents the temporal field of the returned value.

    TemporalField t_field –表示返回值的时间字段。

Return value:

返回值:

The return type of this method is int, it returns the value for the given temporal field from this date-time.

此方法的返回类型为int ,它从该日期时间返回给定时间字段的值。

Example:

例:

// Java program to demonstrate the example
// of get(TemporalField t_field) method
// of LocalDateTime
import java.time.*;
import java.time.temporal.*;
public class GetOfLocalDateTime {public static void main(String args[]) {// Instantiates two LocalDateTime
LocalDateTime da_ti1 = LocalDateTime.parse("2005-10-05T10:10:10");
LocalDateTime da_ti2 = LocalDateTime.now();
// Display da_ti1, da_ti2
System.out.println("LocalDateTime da_ti1 and da_ti2: ");
System.out.println("da_ti1: " + da_ti1);
System.out.println("da_ti2: " + da_ti2);
System.out.println();
// Here, this method gets the value
// for the given field from this date-time
// i.e. we are getting the field value
// MONTH_OF_YEAR from this da_ti1
int get_val = da_ti1.get(ChronoField.MONTH_OF_YEAR);
// Display get_val
System.out.println("da_ti1.get(ChronoField.MONTH_OF_YEAR): " + get_val);
// Here, this method gets the value for the
// given field from this date-time
// i.e. we are getting the field value
// MICRO_OF_SECOND from this da_ti2
get_val = da_ti2.get(ChronoField.MICRO_OF_SECOND);
// Display get_val
System.out.println("da_ti2.get(ChronoField.MICRO_OF_SECOND): " + get_val);
}
}

Output

输出量

LocalDateTime da_ti1 and da_ti2:
da_ti1: 2005-10-05T10:10:10
da_ti2: 2020-06-05T02:20:56.040348da_ti1.get(ChronoField.MONTH_OF_YEAR): 10
da_ti2.get(ChronoField.MICRO_OF_SECOND): 40348

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

java中get接口示例

java中get接口示例_Java LocalDateTime类| 带示例的get()方法相关推荐

  1. java中get接口示例_Java即时类| 带示例的get()方法

    java中get接口示例 即时类的get()方法 (Instant Class get() method) get() method is available in java.time package ...

  2. java 根据类名示例化类_Java LocalDateTime类| 带示例的getNano()方法

    java 根据类名示例化类 LocalDateTime类getNano()方法 (LocalDateTime Class getNano() method) getNano() method is a ...

  3. java的equals方法_Java LocalDateTime类| 带示例的equals()方法

    java的equals方法 LocalDateTime类equals()方法 (LocalDateTime Class equals() method) equals() method is avai ...

  4. Java LocalDateTime类| 带示例的getDayOfWeek()方法

    LocalDateTime类getDayOfWeek()方法 (LocalDateTime Class getDayOfWeek() method) getDayOfWeek() method is ...

  5. Java LocalDateTime类| 带示例的getMinute()方法

    LocalDateTime类getMinute()方法 (LocalDateTime Class getMinute() method) getMinute() method is available ...

  6. java getmonth_Java LocalDateTime类| 带示例的getMonth()方法

    java getmonth LocalDateTime类getMonth()方法 (LocalDateTime Class getMonth() method) getMonth() method i ...

  7. Java LocalDateTime类| 带示例的compareTo()方法

    LocalDateTime类compareTo()方法 (LocalDateTime Class compareTo() method) compareTo() method is available ...

  8. Java LocalDateTime类| 带示例的getDayOfYear()方法

    LocalDateTime类getDayOfYear()方法 (LocalDateTime Class getDayOfYear() method) getDayOfYear() method is ...

  9. getlong_Java LocalDateTime类| 带示例的getLong()方法

    getlong LocalDateTime类的getLong()方法 (LocalDateTime Class getLong() method) getLong() method is availa ...

最新文章

  1. pdb+ipdb 调试 Python代码
  2. php图书信息浏览器,使PHP即时输出结果到浏览器
  3. 在大数据时代,每家公司都要有大数据部门吗?
  4. Go协程池设计思路(Task-Job-Worker)
  5. 工业以太网交换机的软件故障
  6. html表格的系列代码,HTML系列(八):表格(示例代码)
  7. 从SAP BPC中Entity维设计的理念考虑Web程序中类似文档库之类的设计该考虑的东西...
  8. Zephyr NVS文件系统原理及应用
  9. python人脸识别程序如何嵌入到app_开源|手把手教你用Python进行人脸识别(附源代码)...
  10. 【PC工具】windows免安装录屏绿色软件,无需注册无水印绿色录屏软件
  11. 流媒体之RTMP——librtmp拉流测试
  12. TCP/UDP测试工具下载及使用教程
  13. Linux 串口读写
  14. android感应不了夜神模拟器,夜神模拟器使用(检测不到)
  15. 1.Spring Boot使用Apache Curator实现服务的注册和发现「第四章 ZooKeeper Curator应用场景实战」「架构之路ZooKeeper理论和实战」
  16. matlab hurst,基于Matlab的Hurst指数
  17. Echarts图表隐藏X轴和Y轴
  18. VisualStudio 2017 c++安装
  19. POJ - 1061 青蛙的约会
  20. 各类支付通道大全以及支付通道选择

热门文章

  1. java 签名 ecdsa_Java实现ECDSA签名算法
  2. 修改蓝牙耳机按键映射_喜欢玩游戏的不要错过了,五款高性能游戏蓝牙耳机推荐...
  3. php-fpm初始化失败,FPM的初始化 - [ PHP7的内核剖析 ] - 在线原生手册 - php中文网
  4. xampp mysql 卸载_卸载Xampp并安装apache + mysql + php 过程
  5. innobackup备份恢复实操步骤--gtid复制(1)(1)
  6. C#委托、类和事件的验证【C#】
  7. Quartus II 8.1 详解--有图---图片详解 【1讲】
  8. 形象易懂讲解算法I——小波变换
  9. 例题 3-5 生成元 digit generator
  10. Python的threadpool模块