java 根据类名示例化类_Java LocalDateTime类| atOffset()方法与示例
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()方法与示例相关推荐
- java 根据类名示例化类_Java LocalDateTime类| 带示例的getNano()方法
java 根据类名示例化类 LocalDateTime类getNano()方法 (LocalDateTime Class getNano() method) getNano() method is a ...
- java 根据类名示例化类_Java LocalDateTime类| ofInstant()方法与示例
java 根据类名示例化类 LocalDateTime类的Instant()方法 (LocalDateTime Class ofInstant() method) ofInstant() method ...
- java 根据类名示例化类_Java LocalDateTime类| AdjustInto()方法与示例
java 根据类名示例化类 LocalDateTime类AdjustInto()方法 (LocalDateTime Class adjustInto() method) adjustInto() me ...
- java 根据类名示例化类_Java LocalDateTime类| minusMinutes()方法与示例
java 根据类名示例化类 LocalDateTime类minusMinutes()方法 (LocalDateTime Class minusMinutes() method) minusMinute ...
- java 根据类名示例化类_Java LocalDateTime类| isBefore()方法与示例
java 根据类名示例化类 LocalDateTime类isBefore()方法 (LocalDateTime Class isBefore() method) isBefore() method i ...
- java 根据类名示例化类_Java即时类| from()方法与示例
java 根据类名示例化类 即时类from()方法 (Instant Class from() method) from() method is available in java.time pack ...
- java 根据类名示例化类_Java即时类| EpochSecond()方法的示例
java 根据类名示例化类 EpochSecond()方法的即时类 (Instant Class ofEpochSecond() method) Syntax: 句法: public static I ...
- java 根据类名示例化类_Java即时类| plusMillis()方法与示例
java 根据类名示例化类 即时类plusMillis()方法 (Instant Class plusMillis() method) plusMillis() method is available ...
- java 根据类名示例化类_Java MathContext类| 带示例的getRoundingMode()方法
java 根据类名示例化类 MathContext类的getRoundingMode()方法 (MathContext Class getRoundingMode() method) getRound ...
最新文章
- asp.net程序性能优化的七个方面
- mac mysql的安装
- .NET设计模式(2):单件模式(Singleton Pattern)
- (0076)iOS开发之UIWebView嵌套直播平台(不涉及播放器技术的开发)
- 一台linux通过另一台linux访问互联网
- python怎样分析文献综述怎么写_怎么写文献综述?
- java期末试题c卷,JAVA程序设计期末考试试卷及参考答案
- java enum 长度限制_Java中的Enum的使用与分析
- [PyTorch] 卷积函数 and 解卷积函数
- 【简单】基于springboot的学生在线考试系统【老师、学生、管理员】
- Arcgis学习笔记(二)投影和定义投影
- TranslateAnimation详解
- Qt 中文和英文分别使用不同的字体
- 我的2018年考博英语复习计划Share
- 蜘蛛:请求头、响应头、响应码
- Alpha、Beta、RC、GA版本的区别
- libtorch opecv c++ cmake clion
- blinker 第三方库_blinker 库开发注意事项
- 超好用的PDF在线编辑方法
- 时间复杂度分析-大O表示法
热门文章
- DVWA sql注入 WP
- spark将rdd转为string_八、Spark之详解Tranformation算子
- docker run 服务名_在 WSL2.0 的 Ubuntu 18 里使用 Docker
- uipath循环datatable_UiPath之DataTable转换为List和Array
- strtotime()加半个小时_椰子鸡这样做太好吃了,一滴水不用加,鲜香嫩滑,做法非常简单...
- microbit编程_使用图形化编程实现主控板与手机蓝牙通讯(2019.3.25)
- 能让你的Intellij IDEA 起飞的几个设置(设置背景 字体 快捷键 鼠标悬停提示 提示忽略大小写 取消单行显示)
- ubuntu好文收集
- nginx中的nginx.conf.default配置
- 面向视频的全新AI架构 —— 阿里云智能视觉技术全解