Java中的 ZoneOffsetTransitionRule getLocalTime() 方法示例
Java.time.zone.ZoneOffsetTransitionRule类的getLocalTime()方法用于获取发生转换的本地时间对象。
句法:
public LocalTime getLocalTime()
参数:此方法不接受任何参数。
返回值:此方法返回将发生转换的本地时间对象。
以下是说明getLocalTime()方法的示例:
示例 1:
// Java program to demonstrate
// getLocalTime() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
public class GFG {
public static void main(String[] argv)
{
// creating and initializing
// ZoneOffsetTransitionRule Object
ZoneOffsetTransitionRule zonetrans1
= ZoneOffsetTransitionRule
.of(
Month.JANUARY, 12,
DayOfWeek.SUNDAY,
LocalTime.of(03, 24, 45),
false,
ZoneOffsetTransitionRule
.TimeDefinition
.STANDARD,
ZoneOffset.ofTotalSeconds(8),
ZoneOffset.ofTotalSeconds(10),
ZoneOffset.ofTotalSeconds(12));
// getting object of local time
// by using getLocalTime() method
LocalTime loc
= zonetrans1.getLocalTime();
// display the result
System.out.println(
"Local Time : " + loc);
}
}
输出:
Local Time : 03:24:45
示例 2:
// Java program to demonstrate
// getLocalTime() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
public class GFG {
public static void main(String[] argv)
{
// creating and initializing
// ZoneOffsetTransitionRule Object
ZoneOffsetTransitionRule zonetrans1
= ZoneOffsetTransitionRule
.of(
Month.JANUARY, 12,
DayOfWeek.SUNDAY,
LocalTime.of(04, 40, 45),
false,
ZoneOffsetTransitionRule
.TimeDefinition
.STANDARD,
ZoneOffset.ofTotalSeconds(8),
ZoneOffset.ofTotalSeconds(10),
ZoneOffset.ofTotalSeconds(12));
// getting object of local time
// by using getLocalTime() method
LocalTime loc = zonetrans1.getLocalTime();
// display the result
System.out.println("Local Time : " + loc);
}
}
输出:
Local Time : 04:40:45
参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/zone/ZoneOffsetTransitionRule.html#getLocalTime–