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 根據類名示例化類

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542010.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542010.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542010.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Zabbix監控——proxy 分布式監控配置

proxy分布式監控 Zabbix proxy是在大規模分布式監控場景中,采用的一種用以分擔server端壓力的分層結構, proxy可以代替zabbix server檢索客戶端的數據,然后把數據匯報給zabbix server,極大的減輕了server的負載壓力,使…

AutoCAD_acadiso.dwt卡死

2019獨角獸企業重金招聘Python工程師標準>>> 問題描述:每次執行到打開acadiso.dwt就卡死,且電腦顯示有網,確打不開網頁 可能原因:可能是因為AotuCAD是盜版的 解決辦法: 1.在任務管理器中把WSCommCntr.exe進…

else 策略模式去掉if_java – 用狀態/策略模式替換if/else邏輯

我認為你應該使用GoF模式Chain of responsibility.你應該引入兩個接口:1)你將檢查正確條件的條件,例如“如果zip文件不存在”并返回布爾結果 – 如果條件滿足則返回“true”,否則“else”,2)執行策略,它將運行分配有條件的動作,例如: “從指定的URL下載它…

docker簡介與搭建

1 . 對docker的理解: Docker 是一個開源的應用容器引擎,讓開發者可以打包他們的應用以及依賴包到一個可移植的鏡像中,然后發布到任何流行的 Linux或Windows 機器上,也可以實現虛擬化。容器是完全使用沙箱機制,相互之間…

Java BigInteger類| toByteArray()方法與示例

BigInteger類testBit()方法 (BigInteger Class testBit() method) testBit() method is available in java.math package. testBit()方法在java.math包中可用。 testBit() method is used to convert this BigInteger to a byte [] that holds 2s complement denotation of thi…

007_Web to lead

轉載于:https://www.cnblogs.com/bandariFang/p/6229491.html

設置header_Nginx的這些安全設置,你都知道嗎?

Nginx 是最流行的 Web 服務器,可以只占用 2.5 MB 的內存,卻可以輕松處理 1w 的 http 請求。做為網站的入口,Nginx 的安全設置重要性不言而喻。下面帶你一起去認識一下這些安全配置吧!nginx.conf是 Nginx 最主要的配置文件&#xf…

動態路由協議_動態路由協議的類別

動態路由協議Dynamic routing protocols have been divided into 2 categories i.e Distance vector protocols and Link state protocols. Both of these protocols are being explained in detail in this tutorial. 動態路由協議分為距離矢量協議和鏈路狀態協議兩大類 。 本…

docker鏡像創建與優化

1 . 創建鏡像 有兩種方法構建鏡像: docker commit :將運行的容器保存成鏡像Dockerfile:自動構建 使用docker commit 創建鏡像分為三步: 運行容器修改容器將容器保存為鏡像 舉例: [rootdocker ~]# docker load -i…

ISP運營商實驗室測試機架拓撲搭建經驗分享

大家好,有些日子沒更新干貨了,近期難得有假期進行修整,思前顧后還是坐下來聊聊自己長期負責維護和搭建的實驗室環境。廢話不多說,直接上圖。因為圖較大,分上下部分進行上傳。網絡主框架(上)服務…

關于二手交易用戶指南怎么寫_讓用戶拍案叫絕文案怎么寫?試試這3個方法

“共鳴”到底是什么? 為什么有些文章會引起共鳴,而有些則沒有。現在假設為產品家用手持式美容儀寫一份副本。 由于主要重點是“家庭使用”,因此您立即想到了“家庭美容”的口號。 盡管這句話很簡單易懂,但談論起來總是很簡單……似…

結構化程序goto語句_C ++ goto語句| 查找輸出程序| 套裝1

結構化程序goto語句Program 1: 程序1&#xff1a; #include <iostream>#include <math.h>using namespace std;int main(){int num1 1;int num2 0;MY_LABEL:num2 num1 * num1;cout << num2 << " ";num1 num1 pow(2, 0);if (num1 < …

docker倉庫搭建、加密、用戶認證

1 . 含義及理解&#xff1a; 倉庫分為公開倉庫&#xff08;Public&#xff09;和私有倉庫&#xff08;Private&#xff09;兩種形式。最大的公開倉庫是 Docker Hub&#xff0c;存放了數量龐大的鏡像供用戶下載。 國內的公開倉庫包括 Docker Pool等&#xff0c;可以提供大陸用戶…

Centos7+Nginx+Keepalived實現Apache服務的高可用負載均衡

Centos7NginxKeepalived實現Apache服務的高可用&負載均衡今天是2017年的第一天&#xff0c;昨天也就是2016年的最后一天&#xff0c;我嘗試部署了Centos7NginxKeepalived實現WEB服務的高可用負載均衡服務&#xff0c;終于在2017年的第一天前完成了&#xff0c;所以在此分享…

客戶端通過網口啟動可過去的ip_西安交通大學16年3月課程考試《網絡組網技術綜合訓練》作業考核試題...

西安交通大學16年3月課程考試《網絡組網技術綜合訓練》作業考核試題一、單選題(共 20 道試題&#xff0c;共 40 分。)V 1. 下列不屬于服務器內部結構的是()A. CPUB. 電源C. 5類雙絞線D. 北橋芯片滿分&#xff1a;2 分2. 網絡中使用光纜的優點是()A. 便宜B. 容易安裝C. 是一個工…

mcq 隊列_MCQ | 軟件工程基礎知識/簡介(1)

mcq 隊列Q1. Which of the following is a part of the software? Q1。 以下哪個是軟件的一部分&#xff1f; Programs 程式 Documentation 文獻資料 Operating Procedures 運營流程 All of the above 上述所有的 Answer: d. All of the above 答案&#xff1a; d。 上述所有…

docker設置鏡像加速器

設置鏡像加速器 一般情況下&#xff0c;直接從官方倉庫中直接拉取鏡像會比較慢&#xff0c;可以設置鏡像加速器&#xff0c;相當于一個反向代理。以阿里云為例 1 . 首先獲取自己的加速器地址 www.aliyun.com 登陸自己的賬號&#xff08;可以是支付寶賬號&#xff09; 首頁點…

keytool條目_java keytool 常用命令

最近在做ssl連接active directory&#xff0c; 遇到了不少的ssl的問題。連接ssl時會需要用將證書保存到keystore&#xff0c; 而這個步驟剛好就用到了keytool命令。直接敲keytool會有提示如何用這個命令&#xff0c; 但對于完全不懂的我&#xff0c;還是找了下基本命令&#xf…

用JavaScript中的示例進行fill()函數

fill() is a predefined function in JavaScript, which is used to fill all elements of an array with a static value. fill()是JavaScript中的預定義函數&#xff0c;用于用靜態值填充數組的所有元素。 Example: 例&#xff1a; <html><head><title>J…

談談重載(overload)覆蓋(override)與隱藏

這三個概念都是與OO中的多態有關系的。如果單是區別重載與覆蓋這兩個概念是比較容易的&#xff0c;但是隱藏這一概念卻使問題變得有點復雜了&#xff0c;下面說說它們的區別吧。重載是指不同的函數使用相同的函數名&#xff0c;但是函數的參數個數或類型不同。調用的時候根據函…