自1970年1月1日午夜UTC以來,使用TimeUnit類的toMicros()方法獲取TimeUnit對象表示的時間,以MicroSeconds的數量表示。
用法:
public long toMicros(long duration)
參數:此方法接受強製參數持續時間,該持續時間以毫秒為單位。
返回值:此方法將轉換後的持續時間作為MicroSeconds返回。
下麵的程序演示了TimeUnit toMicros()方法的實現:
示例1:
// Java program to demonstrate
// toMicros() method of TimeUnit Class
import java.util.concurrent.*;
import java.util.Date;
class GFG {
public static void main(String args[])
{
// Get current time in milliseconds
long timeInMilliSec = new Date().getTime();
// Create a TimeUnit object
TimeUnit time = TimeUnit.MILLISECONDS;
// Convert milliseconds to MicroSeconds
// using toMicros() method
System.out.println("Time " + timeInMilliSec
+ " milliSeconds in MicroSeconds = "
+ time.toMicros(timeInMilliSec));
}
}
輸出:
Time 1539585538596 milliSeconds in MicroSeconds = 1539585538596000
示例2:
// Java program to demonstrate
// toMicros() method of TimeUnit Class
import java.util.concurrent.*;
import java.util.Calendar;
class GFG {
public static void main(String args[])
{
// Get current time in milliseconds
long timeInMilliSec = Calendar
.getInstance()
.getTimeInMillis();
// Create a TimeUnit object
TimeUnit time = TimeUnit.MILLISECONDS;
// Convert milliseconds to MicroSeconds
// using toMicros() method
System.out.println("Time " + timeInMilliSec
+ " milliSeconds in MicroSeconds = "
+ time.toMicros(timeInMilliSec));
}
}
輸出:
Time 1539585540908 milliSeconds in MicroSeconds = 1539585540908000
相關用法
- Java TimeUnit toMillis()用法及代碼示例
- Java TimeUnit toHours()用法及代碼示例
- Java TimeUnit toSeconds()用法及代碼示例
- Java TimeUnit toMinutes()用法及代碼示例
- Java TimeUnit toDays()用法及代碼示例
- Java TimeUnit values()用法及代碼示例
- Java TimeUnit sleep()用法及代碼示例
- Java TimeUnit valueOf()用法及代碼示例
- Java TimeUnit convert()用法及代碼示例
- Java TimeUnit toNanos()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java lang.Long.lowestOneBit()用法及代碼示例
注:本文由純淨天空篩選整理自RishabhPrabhu大神的英文原創作品 TimeUnit toMicros() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。