SimpleTimeZone类的getOffset()方法 (SimpleTimeZone Class getOffset() method)
Syntax:
句法:
public int getOffset(int era's , int yy, int mm, int dd, int DOW, int ms);
public int getOffset(long dd);
getOffset() method is available in java.util package.
getOffset()方法在java.util包中可用。
getOffset(int era's , int yy, int mm, int dd, int dow, int ms) method is used to get the variations in milliseconds between local time and UTC.
getOffset(int age's,int yy,int mm,int dd,int dow,int ms)方法用于获取本地时间和UTC之间的毫秒数变化。
getOffset(long dd) method is used to return the offset of this simple time zone from UTC at the given date (dd).
getOffset(long dd)方法用于返回给定日期(dd)时此简单时区与UTC的偏移量。
These methods may throw an exception at the time of getting offset.
这些方法在获取偏移量时可能会引发异常。
IllegalArgumentException: This exception may throw when anyone of the parameter is not in a range.
IllegalArgumentException :当任何参数不在范围内时,可能引发此异常。
These are non-static methods and it is accessible with class object only and if we try to access these methods with class name then we will get an error.
这些是非静态方法,并且只能通过类对象进行访问,如果尝试使用类名访问这些方法,则会收到错误消息。
Parameter(s):
参数:
In the first case, getOffset(int era's , int yy, int mm, int dd, int dow, int ms)"
在第一种情况下, getOffset(int age's,int yy,int mm,int dd,int dow,int ms)“
- int era's – represents the era of the specified date.
- int age's –代表指定日期的时代。
- int yy – represents the year of the specified date.
- int yy –表示指定日期的年份。
- int mm – represents the month of the specified date.
- int mm –表示指定日期的月份。
- int dd – represents the day of week of the specified date.
- int dd –表示指定日期的星期几。
- int dow – represents the year of the specified date.
- int dow –表示指定日期的年份。
- int ms – represents the milliseconds in Standard Local Time.
- int ms –表示标准本地时间的毫秒数。
In the second case, getOffset(long dd),
在第二种情况下, getOffset(long dd) ,
- long dd – represents dates and it is represented in milliseconds.
- long dd –代表日期,以毫秒为单位。
Return value:
返回值:
In both the cases, the return type of the method is int - It adds returned milliseconds to UTC to get local time.
在这两种情况下,方法的返回类型均为int-将返回的毫秒数添加到UTC以获取本地时间。
Example:
例:
// Java program to demonstrate the example
// of getOffset() method of SimpleTimeZone
import java.util.*;
public class GetOffsetOfSimpleTimeZone {
public static void main(String args[]) {
// Instantiates SimpleTimeZone object
SimpleTimeZone s_tz = new SimpleTimeZone(360, "FRANCE");
// Display s_tz
System.out.println("s_tz: " + s_tz);
// By using getOffset() method is to
// get the offset according the given arguments
System.out.print("s_tz.getOffset(era's, yy, mm,dd,dow,time): ");
System.out.println(s_tz.getOffset(1, 2009, 3, 3, 3, 100));
// By using getOffset() method is to
// get the offset according the given date
System.out.print("s_tz.getOffset(long d): ");
System.out.println(s_tz.getOffset(Calendar.ZONE_OFFSET));
}
}
Output
输出量
s_tz: java.util.SimpleTimeZone[id=FRANCE,offset=360,dstSavings=3600000,useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]
s_tz.getOffset(era's, yy, mm,dd,dow,time): 360
s_tz.getOffset(long d): 360
翻译自: https://www.includehelp.com/java/simpletimezone-getoffset-method-with-example.aspx