Java 中的 ZoneOffsetTransitionRule getLocalTime()方法,示例
原文:https://www . geeksforgeeks . org/zoneoffsettransitionrule-getlocaltime-in-Java-method-with-example/
类的 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
版权属于:月萌API www.moonapi.com,转载请注明出处