java 根据类名示例化类

LocalDateTime类atOffset()方法 (LocalDateTime Class atOffset() method)

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

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

  • atOffset() method is used to create an OffsetDateTime to merge this LocalDateTime with the given offset.

    atOffset()方法用于创建OffsetDateTime,以将此LocalDateTime与给定的偏移量合并。

  • atOffset() 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.

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

  • atOffset() method does not throw an exception at the time of representing LocalDateTime.

    atOffset()方法在表示LocalDateTime时不会引发异常。

Syntax:

句法:

    public OffsetDateTime atOffset(ZoneOffset off);

Parameter(s):

参数:

  • ZoneOffset off – represents the zone offset to merge with this LocalDateTime.

    ZoneOffset off –表示要与此LocalDateTime合并的区域偏移量。

Return value:

返回值:

The return type of this method is OffsetDateTime, it returns OffsetDateTime object that holds the value merged this LocalDateTime with the given offset.

此方法的返回类型为OffsetDateTime ,它返回OffsetDateTime对象,该对象包含将此LocalDateTime与给定的偏移量合并的值。

Example:

例:

// Java program to demonstrate the example
// of atOffset(ZoneOffset off) method
// of LocalDateTime
import java.time.*;
public class AtOffsetOfLocalDateTime {public static void main(String args[]) {// Instantiates two LocalDateTime
// and a ZonedOffset
LocalDateTime da_ti1 = LocalDateTime.parse("2005-10-05T10:10:10");
LocalDateTime da_ti2 = LocalDateTime.now();
ZoneOffset off = ZoneOffset.ofHoursMinutes(2, 2);
// Display da_ti1, da_ti2
// and off
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 creates an OffsetDateTime
// by merging this date-time (da_ti1) with
// the given offset (off) i.e.
// da_ti1 + off(in hours , in minutes)
OffsetDateTime off_da_time = da_ti1.atOffset(off);
// Display updated off_da_time
System.out.println("da_ti1.atOffset(off): " + off_da_time);
// Here, this method creates an OffsetDateTime
// by merging this date-time (da_ti2) with
// the given offset (off) i.e.
// da_ti2 + off(in hours)
off_da_time = da_ti2.atOffset(ZoneOffset.ofHours(4));
// Display updated off_da_time
System.out.print("da_ti2.atOffset(ZoneOffset.ofHours(4)): ");
System.out.println(off_da_time);
}
}

Output

输出量

LocalDateTime da_ti1 and da_ti2:
da_ti1: 2005-10-05T10:10:10
da_ti2: 2020-06-04T08:02:20.579734da_ti1.atOffset(off): 2005-10-05T10:10:10+02:02
da_ti2.atOffset(ZoneOffset.ofHours(4)): 2020-06-04T08:02:20.579734+04:00

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

java 根据类名示例化类

java 根据类名示例化类_Java LocalDateTime类| atOffset()方法与示例相关推荐

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

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

  2. java 根据类名示例化类_Java LocalDateTime类| ofInstant()方法与示例

    java 根据类名示例化类 LocalDateTime类的Instant()方法 (LocalDateTime Class ofInstant() method) ofInstant() method ...

  3. java 根据类名示例化类_Java LocalDateTime类| AdjustInto()方法与示例

    java 根据类名示例化类 LocalDateTime类AdjustInto()方法 (LocalDateTime Class adjustInto() method) adjustInto() me ...

  4. java 根据类名示例化类_Java LocalDateTime类| minusMinutes()方法与示例

    java 根据类名示例化类 LocalDateTime类minusMinutes()方法 (LocalDateTime Class minusMinutes() method) minusMinute ...

  5. java 根据类名示例化类_Java LocalDateTime类| isBefore()方法与示例

    java 根据类名示例化类 LocalDateTime类isBefore()方法 (LocalDateTime Class isBefore() method) isBefore() method i ...

  6. java 根据类名示例化类_Java即时类| from()方法与示例

    java 根据类名示例化类 即时类from()方法 (Instant Class from() method) from() method is available in java.time pack ...

  7. java 根据类名示例化类_Java即时类| EpochSecond()方法的示例

    java 根据类名示例化类 EpochSecond()方法的即时类 (Instant Class ofEpochSecond() method) Syntax: 句法: public static I ...

  8. java 根据类名示例化类_Java即时类| plusMillis()方法与示例

    java 根据类名示例化类 即时类plusMillis()方法 (Instant Class plusMillis() method) plusMillis() method is available ...

  9. java 根据类名示例化类_Java MathContext类| 带示例的getRoundingMode()方法

    java 根据类名示例化类 MathContext类的getRoundingMode()方法 (MathContext Class getRoundingMode() method) getRound ...

最新文章

  1. asp.net程序性能优化的七个方面
  2. mac mysql的安装
  3. .NET设计模式(2):单件模式(Singleton Pattern)
  4. (0076)iOS开发之UIWebView嵌套直播平台(不涉及播放器技术的开发)
  5. 一台linux通过另一台linux访问互联网
  6. python怎样分析文献综述怎么写_怎么写文献综述?
  7. java期末试题c卷,JAVA程序设计期末考试试卷及参考答案
  8. java enum 长度限制_Java中的Enum的使用与分析
  9. [PyTorch] 卷积函数 and 解卷积函数
  10. 【简单】基于springboot的学生在线考试系统【老师、学生、管理员】
  11. Arcgis学习笔记(二)投影和定义投影
  12. TranslateAnimation详解
  13. Qt 中文和英文分别使用不同的字体
  14. 我的2018年考博英语复习计划Share
  15. 蜘蛛:请求头、响应头、响应码
  16. Alpha、Beta、RC、GA版本的区别
  17. libtorch opecv c++ cmake clion
  18. blinker 第三方库_blinker 库开发注意事项
  19. 超好用的PDF在线编辑方法
  20. 时间复杂度分析-大O表示法

热门文章

  1. DVWA sql注入 WP
  2. spark将rdd转为string_八、Spark之详解Tranformation算子
  3. docker run 服务名_在 WSL2.0 的 Ubuntu 18 里使用 Docker
  4. uipath循环datatable_UiPath之DataTable转换为List和Array
  5. strtotime()加半个小时_椰子鸡这样做太好吃了,一滴水不用加,鲜香嫩滑,做法非常简单...
  6. microbit编程_使用图形化编程实现主控板与手机蓝牙通讯(2019.3.25)
  7. 能让你的Intellij IDEA 起飞的几个设置(设置背景 字体 快捷键 鼠标悬停提示 提示忽略大小写 取消单行显示)
  8. ubuntu好文收集
  9. nginx中的nginx.conf.default配置
  10. 面向视频的全新AI架构 —— 阿里云智能视觉技术全解