duration java_Java Duration類| toNanos()方法與示例

duration java

Duration Class toNanos()方法 (Duration Class toNanos() method)

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

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

  • toNanos() method is used to convert this Duration into the number of nanoseconds.

    toNanos()方法用于將此Duration轉換為納秒數。

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

    toNanos()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • toNanos() method does not throw an exception at the time of converting this Duration to nanoseconds.

    將此Duration轉換為納秒時, toNanos()方法不會引發異常。

Syntax:

句法:

    public long toNanos();

Parameter(s):

參數:

  • None

    沒有

Return value:

返回值:

The return type of this method is long, it returns the number of nanoseconds exists in this Duration.

此方法的返回類型為long ,它返回此Duration中存在的納秒數。

Example:

例:

// Java program to demonstrate the example 
// of long toNanos() method of Duration
import java.time.*;
public class ToNanosOfDuration {
public static void main(String args[]) {
// Instantiates two Duration objects
Duration du1 = Duration.ofSeconds(1);
Duration du2 = Duration.parse("P0DT0H1M");
// Display du1 and du2
System.out.println("du1: " + du1);
System.out.println("du2: " + du2);
// represents this Duration du1 in seconds into
// number of nanoseconds
long to_nanos = du1.toNanos();
// Display to_nanos
System.out.println("du1.toNanos(): " + to_nanos);
// represents this Duration du2 in minutes into
// number of nanoseconds
to_nanos = du2.toNanos();
// Display to_nanos
System.out.println("du2.toNanos(): " + to_nanos);
}
}

Output

輸出量

du1: PT1S
du2: PT1M
du1.toNanos(): 1000000000
du2.toNanos(): 60000000000

翻譯自: https://www.includehelp.com/java/duration-tonanos-method-with-example.aspx

duration java

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

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

相關文章

java 負載均衡_java負載均衡 - 歲月靜好I的個人空間 - OSCHINA - 中文開源技術交流社區...

作用對系統的高可用,網絡壓力的緩解,處理能力擴容的重要手段之一。服務器負載我們通常所說的負載是指:服務器負載軟硬件負載服務器負載又分為:軟件負載--硬件負載軟件負載:通過在服務器上安裝一些具有負載功能或模塊的…

b tree和b+tree_B TREE實施

b tree和btreeB TREE及其操作簡介 (Introduction to B TREE and its operations) A B tree is designed to store sorted data and allows search, insertion and deletion operation to be performed in logarithmic time. As In multiway search tree, there are so many nod…

黑色背景下,將照片內封閉空心圖案的空心區域染成Cyan并保存

在黑色背景下,將照片內封閉空心圖案的空心區域染色 import cv2 import numpy as np img cv2.imread(E:\Python-workspace\OpenCV\OpenCV/beyond.png,1)#第一個參數為選擇照片的路徑,注意照片路徑最后一個為正斜杠其他都為反斜杠;第二個參數…

Ubuntu輸入su提示認證失敗的解決方法

Ubuntu輸入su提示認證失敗的解決方法 啟動ubuntu服務時竟然提示權限不夠,用su切換,輸入密碼提示認證失敗,這下搞了吧,后來一經查閱原來Ubuntu安裝后,root用戶默認是被鎖定了的,不允許登錄,也不允…

SDP協議基本分析(RTSP、WebRTC使用)

目錄一、介紹二、標準 SDP 規范1. SDP 的格式2. SDP 的結構(1)會話描述(2)媒體描述三、WebRTC 中的 SDP一、介紹 SDP(Session Description Protocal)以文本描述各端(PC 端、Mac 端、Android 端…

MFC六大關鍵技術(第四部分)——永久保存(串行化)

MFC 六大關鍵技術 ( 第四部分 ) ——永久保存(串行化) 先用一句話來說明永久保存的重要:弄懂它以后,你就越來越像個程序員了! 如果我們的程序不需要永久保存,那幾乎可以肯定是一個小玩兒。那怕我們的記事本…

在網絡中配置思科交換機

By default, all ports of a switch are enabled. As we are talking about layer 2 switching, there is no need to configure IP address or any routing protocol on the switch. In such a situation, the configuration is not focused on the switch. 缺省情況下&#…

黑色背景下,描繪照片的輪廓形狀并保存

描繪照片的輪廓形狀并保存 import cv2 from matplotlib import pyplot as plt # 1.先找到輪廓 img cv2.imread(E:\Python-workspace\OpenCV\OpenCV/beyond.png, 0) _, thresh cv2.threshold(img, 0, 255, cv2.THRESH_BINARY cv2.THRESH_OTSU) image, conturs, hierarchy c…

java pdf合并_Java 合并、拆分PDF文檔

本文將介紹如何在Java程序中合并及拆分PDF文檔,合并文檔時,包括合并多個不同PDF文檔為一個文檔,以及合并PDF文檔的不同頁面為一頁;拆分文檔是,包括將PDF文檔按每一頁拆分,以及按指定頁數范圍來拆分。下面將…

HDU4405 期望

對于期望,首先,對于這個公式中p表示概率,x表示隨機變量 展開則為 ex p1*x1p2*x2p3*x3....... 對于本題 假設 ex[ i ]表示當前 i 走到 n 的期望值。所以若 i 處沒有飛機,ex[ i ]sigma(1/6*ex[ik])1 其中(k1...6) (1表示…

調用本地電腦攝像頭并進行按P進行捕獲照片并保存,按下Q退出

調用本地電腦攝像頭并進行按P進行捕獲照片并保存,按下Q退出 灰度攝像頭顯示: import cv2 cap cv2.VideoCapture(0) if not cap.isOpened():print("Cannot open camera")exit() while True:# 逐幀捕獲ret, frame cap.read()# 如果正確讀取幀…

intersect函數_PHP array_intersect()函數與示例

intersect函數PHP array_intersect()函數 (PHP array_intersect() Function ) array_intersect() function is used to find the matched elements from two or more elements. Function “array_intersect()” compares the values of the first array with the other arrays …

很全的SQL注入語句

1、返回的是連接的數據庫名and db_name()>02、作用是獲取連接用戶名and user>03、將數據庫備份到Web目錄下面;backup database 數據庫名 to diskc:\inetpub\wwwroot\1.db;--4、顯示SQL系統版本and 1(select VERSION) 或and 1convert(int,version)--5、判斷xp_cmdshell擴展…

使用DataTable更新數據庫

1、修改數據 DataRow dr hRDataSet.Tables["emp"].Rows.Find(textBox3.Text);//DataRow dr hRDataSet.Tables["emp"].Select("id"textBox3.Text)[0];dr.BeginEdit();dr["name"] textBox1.Text;dr.EndEdit();SqlCommandBuilder cmdn…

java異常體系_JAVA異常體系結構詳解

一、什么是異常異常:程序在運行過程中發生由于硬件設備問題、軟件設計錯誤等導致的程序異常事件。(在Java等面向對象的編程語言中)異常本身是一個對象,產生異常就是產生了一個異常對象。 ——百度百科二、異常體系Java把異常當作對象來處理&#xf…

對照片質量進行壓縮

對照片質量進行壓縮 其實無論是jpg還是png都是已經壓縮編碼化的格式罷了,原圖片的大小要遠遠大于壓縮編碼后的格式 1,像素:圖片放大到一定程度之后的一個個的小方塊 2,RGB:每一個像素(小方塊)都…

Silverlight訪問 Apache服務器(Tomcat,Geronimo)中部署的Webservice

Silverlight 訪問 Apache服務器中的Webservice 開發環境 Vs2010 、 Silverlight4 、 Java Jdk1.6 U 21 、 Apache-tomcat-6.0.20 、 Myeclipse8.5 、 Apache-ant-1.8.1 、 Axis2 、 Geronimo-tomcat6-javaee5-2.2. 下載地址: Apache-tomcat : http://apa…

那些幫助你成為優秀前端工程師的講座——《性能篇》

這篇文章是前端優秀講座和討論列表系列連載第七篇,介紹前端性能優化技巧。前端領域發展迅速,只有時刻掌握前端發展趨勢和技術動態,學習前沿的開發思想和理念才能讓自己跟上時代的步伐,保持自己的技術優勢。 您可能感興趣的相關文章…

mca終端_MCA的完整形式是什么?

mca終端1)MCA:計算機應用碩士 (1) MCA: Master of Computer Application) MCA is an abbreviation of Master of Computer Application. It is a masters degree program for post-graduation in Computer applications. This post-graduate course duration is abo…

鋼鐵俠java_現代版“鋼鐵俠”,無所不能的程序員,java工程師實現人造器官!...

一位名叫利亞姆澤貝迪(Liam Zebedee)的軟件工程師已經厭倦了糖尿病患者的生活挑戰,因此他決定入侵他的胰島素泵,并將其轉變成一種嶄新的高科技胰腺胰腺。Zebedee詳細介紹了查找和訂購零件的過程,為智能胰島素泵編寫軟件的代碼以及在其博客中組…