当前位置: 首页>>代码示例>>Java>>正文


Java TimeZone.getRawOffset方法代码示例

本文整理汇总了Java中java.util.TimeZone.getRawOffset方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.getRawOffset方法的具体用法?Java TimeZone.getRawOffset怎么用?Java TimeZone.getRawOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.TimeZone的用法示例。


在下文中一共展示了TimeZone.getRawOffset方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTimeZoneByOffsets

import java.util.TimeZone; //导入方法依赖的package包/类
public static Map<Integer, ArrayList<TimeZone>> getTimeZoneByOffsets(Collection<TimeZone> timeZones) {
	TreeMap<Integer, ArrayList<TimeZone>> result = new TreeMap<Integer, ArrayList<TimeZone>>();
	if (timeZones != null) {
		Iterator<TimeZone> it = timeZones.iterator();
		while (it.hasNext()) {
			TimeZone timeZone = it.next();
			int timeZoneOffset = timeZone.getRawOffset();
			ArrayList<TimeZone> offsetTimeZones;
			if (!result.containsKey(timeZoneOffset)) {
				offsetTimeZones = new ArrayList<TimeZone>();
				result.put(timeZoneOffset, offsetTimeZones);
			} else {
				offsetTimeZones = result.get(timeZoneOffset);
			}
			offsetTimeZones.add(timeZone);
		}
	}
	return result;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:20,代码来源:DateUtil.java

示例2: hasSameRules

import java.util.TimeZone; //导入方法依赖的package包/类
/**
 * Returns true if this zone has the same raw GMT offset value and
 * transition table as another zone info. If the specified
 * TimeZone object is not a ZoneInfoOld instance, this method returns
 * true if the specified TimeZone object has the same raw GMT
 * offset value with no daylight saving time.
 *
 * @param other the ZoneInfoOld object to be compared with
 * @return true if the given <code>TimeZone</code> has the same
 * GMT offset and transition information; false, otherwise.
 */
public boolean hasSameRules(TimeZone other) {
    if (this == other) {
        return true;
    }
    if (other == null) {
        return false;
    }
    if (!(other instanceof ZoneInfoOld)) {
        if (getRawOffset() != other.getRawOffset()) {
            return false;
        }
        // if both have the same raw offset and neither observes
        // DST, they have the same rule.
        if ((transitions == null)
            && (useDaylightTime() == false)
            && (other.useDaylightTime() == false)) {
            return true;
        }
        return false;
    }
    if (getLastRawOffset() != ((ZoneInfoOld)other).getLastRawOffset()) {
        return false;
    }
    return (checksum == ((ZoneInfoOld)other).checksum);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:ZoneInfoOld.java

示例3: getZonewiseGeneratedTimestamp

import java.util.TimeZone; //导入方法依赖的package包/类
private static String getZonewiseGeneratedTimestamp(String timestampValue) {
TimeZone timezone = TimeZone.getDefault();
int zoneOffset = timezone.getRawOffset();

timestampValue = timestampValue.replace("'", "");

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
      String newTimestampString = null;
try {
	date = formatter.parse(timestampValue);
      } catch (ParseException parseException) {
          LOG.error("Failed to parse input :" + timestampValue + " to date format 'yyyy-MM-dd HH:mm:ss'" + parseException.getMessage());
      }

      if (date != null) {
          Long timestampInMillis = date.getTime();
          long timestampasperzone = timestampInMillis - zoneOffset;

          Date newtimestamp = new Date(timestampasperzone);
          newTimestampString = formatter.format(newtimestamp);

      }
      newTimestampString = (newTimestampString==null) ? timestampValue : newTimestampString;
      return "'" + newTimestampString + "'";
  }
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:27,代码来源:LingualQueryCreator.java

示例4: a

import java.util.TimeZone; //导入方法依赖的package包/类
public List<String> a(TimeZone timeZone, TimeZone timeZone2, List<String> list) {
    if (timeZone.equals(timeZone2)) {
        return list;
    }
    long rawOffset = (long) (((timeZone.getRawOffset() - timeZone2.getRawOffset()) / 1000) /
            60);
    long parseLong = Long.parseLong(((String) list.get(0)).split(":")[0]);
    long parseLong2 = Long.parseLong(((String) list.get(0)).split(":")[1]);
    parseLong = ((((parseLong * 60) + parseLong2) - rawOffset) + 1440) % 1440;
    long parseLong3 = (((Long.parseLong(((String) list.get(1)).split(":")[1]) + (60 * Long
            .parseLong(((String) list.get(1)).split(":")[0]))) - rawOffset) + 1440) % 1440;
    List arrayList = new ArrayList();
    List list2 = arrayList;
    list2.add(String.format("%1$02d:%2$02d", new Object[]{Long.valueOf(parseLong / 60), Long
            .valueOf(parseLong % 60)}));
    list2 = arrayList;
    list2.add(String.format("%1$02d:%2$02d", new Object[]{Long.valueOf(parseLong3 / 60), Long
            .valueOf(parseLong3 % 60)}));
    return arrayList;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:f.java

示例5: calculateGMTOffset

import java.util.TimeZone; //导入方法依赖的package包/类
private String calculateGMTOffset()
{
    String sign = "+";
    TimeZone timeZone = TimeZone.getDefault();
    int offset = timeZone.getRawOffset();
    if (offset < 0)
    {
        sign = "-";
        offset = -offset;
    }
    int hours = offset / (60 * 60 * 1000);
    int minutes = (offset - (hours * 60 * 60 * 1000)) / (60 * 1000);

    try
    {
        if (timeZone.useDaylightTime() && timeZone.inDaylightTime(this.getDate()))
        {
            hours += sign.equals("+") ? 1 : -1;
        }
    }
    catch (ParseException e)
    {
        // we'll do our best and ignore daylight savings
    }

    return "GMT" + sign + convert(hours) + ":" + convert(minutes);
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:28,代码来源:DERGeneralizedTime.java

示例6: getRawOffset

import java.util.TimeZone; //导入方法依赖的package包/类
/**
 * Gets the offset of the time zone at which the current time is relative to the GMT +0:00 time zone
 *
 * @return int offset
 */
public static int getRawOffset() {
    TimeZone tz = TimeZone.getDefault();
    int offset = tz.getRawOffset();
    System.out.println("getRawOffset: offset=" + offset);//28800000 of china
    return offset / 1000;
}
 
开发者ID:Jusenr,项目名称:androidtools,代码行数:12,代码来源:DateUtils.java

示例7: convertTimeZone

import java.util.TimeZone; //导入方法依赖的package包/类
/**
 * 时区转换
 *
 * @param sourceDate
 * @param sourceTimeZone
 * @param targetTimeZone
 * @return
 */
public static Date convertTimeZone(Date sourceDate, TimeZone sourceTimeZone, TimeZone targetTimeZone) {

    if(null == sourceDate) {
        return null;
    }

    Long targetTime = sourceDate.getTime() - sourceTimeZone.getRawOffset() + targetTimeZone.getRawOffset();
    return new Date(targetTime);
}
 
开发者ID:arccode,项目名称:wechat-pay-sdk,代码行数:18,代码来源:DateUtils.java

示例8: compare

import java.util.TimeZone; //导入方法依赖的package包/类
@Override
   public int compare(TimezoneDTO o1, TimezoneDTO o2) {
if (o1 != null && o2 != null && o1.getTimeZoneId() != null && o2.getTimeZoneId() != null) {
    TimeZone o1TimeZone = TimeZone.getTimeZone(o1.getTimeZoneId());
    TimeZone o2TimeZone = TimeZone.getTimeZone(o2.getTimeZoneId());
    int rawOffsetDifference = o1TimeZone.getRawOffset() - o2TimeZone.getRawOffset();
    int compareResult = (rawOffsetDifference != 0) ? rawOffsetDifference
	    : o1TimeZone.getID().compareTo(o2TimeZone.getID());
    return compareResult;
} else if (o1 != null) {
    return 1;
} else {
    return -1;
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:TimezoneDTOComparator.java

示例9: start

import java.util.TimeZone; //导入方法依赖的package包/类
/**
 * Prepare for the beginning of active use of the public methods of this
 * component.  This method should be called after <code>configure()</code>,
 * and before any of the public methods of the component are utilized.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
public void start() throws LifecycleException {

    // Validate and update our current component state
    if (started)
        throw new LifecycleException
            (sm.getString("accessLogValve.alreadyStarted"));
    lifecycle.fireLifecycleEvent(START_EVENT, null);
    started = true;

    // Initialize the timeZone, Date formatters, and currentDate
    TimeZone tz = TimeZone.getDefault();
    timeZone = "" + (tz.getRawOffset() / (60 * 60 * 10));
    if (timeZone.length() < 5)
        timeZone = timeZone.substring(0, 1) + "0" +
            timeZone.substring(1, timeZone.length());
    dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
    dateFormatter.setTimeZone(tz);
    dayFormatter = new SimpleDateFormat("dd");
    dayFormatter.setTimeZone(tz);
    monthFormatter = new SimpleDateFormat("MM");
    monthFormatter.setTimeZone(tz);
    yearFormatter = new SimpleDateFormat("yyyy");
    yearFormatter.setTimeZone(tz);
    timeFormatter = new SimpleDateFormat("HH:mm:ss");
    timeFormatter.setTimeZone(tz);
    currentDate = new Date();
    dateStamp = dateFormatter.format(currentDate);

    open();

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:40,代码来源:AccessLogValve.java

示例10: TestEpochStartFields

import java.util.TimeZone; //导入方法依赖的package包/类
public void TestEpochStartFields() {
    String[][] lt = {
        {"en", "US", "US/Pacific"},        /* First day = 1, Minimum day = 1 */
        {"en", "US", "America/Anchorage"}, /* First day = 1, Minimum day = 1 */
        {"en", "TO", "Pacific/Tongatapu"}, /* First day = 1, Minimum day = 1 */
        {"en", "MH", "Pacific/Majuro"},    /* First day = 1, Minimum day = 1 */
        {"ja", "JP", "Asia/Tokyo"},        /* First day = 1, Minimum day = 1 */
        {"iw", "IL", "Asia/Jerusalem"},    /* First day = 1, Minimum day = 1 */
        {"hi", "IN", "Asia/Jakarta"},      /* First day = 1, Minimum day = 1 */
        {"en", "GB", "Europe/London"},     /* First day = 2, Minimum day = 1 */
        {"en", "GB", "GMT"},               /* First day = 2, Minimum day = 1 */
        {"de", "DE", "Europe/Berlin"},     /* First day = 2, Minimum day = 4 */
        {"ar", "EG", "Africa/Cairo"}};     /* First day = 7, Minimum day = 1 */

    int[][] goldenData = {
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, -28800000, 0},
        {1, 1969, 11, 1, 5, 31, 365, 4, 5, 1, 11, 23, 0, 0, 0, -36000000, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 46800000, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 43200000, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 32400000, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 7200000, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 25200000, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 1, 1, 0, 0, 0, 3600000, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 3600000, 0},
        {1, 1970, 0, 1, 1, 1, 1, 5, 1, 0, 0, 0, 0, 0, 0, 7200000, 0}};

    Locale savedLocale = Locale.getDefault();
    TimeZone savedTimeZone = TimeZone.getDefault();

    try {
        for (int j = 0; j < lt.length; j++) {
            Locale l = new Locale(lt[j][0], lt[j][1]);
            TimeZone z = TimeZone.getTimeZone(lt[j][2]);
            Locale.setDefault(l);
            TimeZone.setDefault(z);
            Calendar c = Calendar.getInstance();
            Date d = new Date(-z.getRawOffset());

            int val;
            int[] EPOCH_FIELDS = goldenData[j];
            c.setTime(d);

            boolean err = false;
            for (int i = 0; i < calendarFieldNames.length; ++i) {
                if ((val = c.get(i)) != EPOCH_FIELDS[i]) {
                    errln("Wrong value: " + val
                            + " for field(" + calendarFieldNames[i]
                            + "), expected: " + EPOCH_FIELDS[i]);
                    err = true;
                }
            }
            if (err) {
                errln("Failed: \n\tDate=" + d + "\n\tTimeZone=" + z
                        + "\n\tLocale=" + l + "\n\tCalendar=" + c);
            }
        }
    } finally {
        Locale.setDefault(savedLocale);
        TimeZone.setDefault(savedTimeZone);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:63,代码来源:CalendarTest.java

示例11: getAvailableIDs

import java.util.TimeZone; //导入方法依赖的package包/类
/**
 * Gets all available IDs that have the same value as the
 * specified raw GMT offset.
 *
 * @param rawOffset the GMT offset in milliseconds. This
 * value should not include any daylight saving time.
 *
 * @return an array of time zone IDs.
 */
public static String[] getAvailableIDs(int rawOffset) {
    String[] result;
    List<String> matched = new ArrayList<>();
    List<String> IDs = ZoneInfoFile.getZoneIDs();
    int[] rawOffsets = ZoneInfoFile.getRawOffsets();

loop:
    for (int index = 0; index < rawOffsets.length; index++) {
        if (rawOffsets[index] == rawOffset) {
            byte[] indices = ZoneInfoFile.getRawOffsetIndices();
            for (int i = 0; i < indices.length; i++) {
                if (indices[i] == index) {
                    matched.add(IDs.get(i++));
                    while (i < indices.length && indices[i] == index) {
                        matched.add(IDs.get(i++));
                    }
                    break loop;
                }
            }
        }
    }

    // We need to add any zones from the excluded zone list that
    // currently have the same GMT offset as the specified
    // rawOffset. The zones returned by this method may not be
    // correct as of return to the caller if any GMT offset
    // transition is happening during this GMT offset checking...
    List<String> excluded = ZoneInfoFile.getExcludedZones();
    if (excluded != null) {
        for (String id : excluded) {
            TimeZone zi = getTimeZone(id);
            if (zi != null && zi.getRawOffset() == rawOffset) {
                matched.add(id);
            }
        }
    }

    result = new String[matched.size()];
    matched.toArray(result);
    return result;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:51,代码来源:ZoneInfoOld.java

示例12: getCalendarDate

import java.util.TimeZone; //导入方法依赖的package包/类
public CalendarDate getCalendarDate(long millis, CalendarDate date) {
    int ms = 0;             // time of day
    int zoneOffset = 0;
    int saving = 0;
    long days = 0;          // fixed date

    // adjust to local time if `date' has time zone.
    TimeZone zi = date.getZone();
    if (zi != null) {
        int[] offsets = new int[2];
        if (zi instanceof ZoneInfo) {
            zoneOffset = ((ZoneInfo)zi).getOffsets(millis, offsets);
        } else {
            zoneOffset = zi.getOffset(millis);
            offsets[0] = zi.getRawOffset();
            offsets[1] = zoneOffset - offsets[0];
        }

        // We need to calculate the given millis and time zone
        // offset separately for java.util.GregorianCalendar
        // compatibility. (i.e., millis + zoneOffset could cause
        // overflow or underflow, which must be avoided.) Usually
        // days should be 0 and ms is in the range of -13:00 to
        // +14:00. However, we need to deal with extreme cases.
        days = zoneOffset / DAY_IN_MILLIS;
        ms = zoneOffset % DAY_IN_MILLIS;
        saving = offsets[1];
    }
    date.setZoneOffset(zoneOffset);
    date.setDaylightSaving(saving);

    days += millis / DAY_IN_MILLIS;
    ms += (int) (millis % DAY_IN_MILLIS);
    if (ms >= DAY_IN_MILLIS) {
        // at most ms is (DAY_IN_MILLIS - 1) * 2.
        ms -= DAY_IN_MILLIS;
        ++days;
    } else {
        // at most ms is (1 - DAY_IN_MILLIS) * 2. Adding one
        // DAY_IN_MILLIS results in still negative.
        while (ms < 0) {
            ms += DAY_IN_MILLIS;
            --days;
        }
    }

    // convert to fixed date (offset from Jan. 1, 1 (Gregorian))
    days += EPOCH_OFFSET;

    // calculate date fields from the fixed date
    getCalendarDateFromFixedDate(date, days);

    // calculate time fields from the time of day
    setTimeOfDay(date, ms);
    date.setLeapYear(isLeapYear(date));
    date.setNormalized(true);
    return date;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:59,代码来源:AbstractCalendar.java

示例13: toStringImpl

import java.util.TimeZone; //导入方法依赖的package包/类
@SuppressWarnings("fallthrough")
private static String toStringImpl(final Object self, final int format) {
    final NativeDate nd = getNativeDate(self);

    if (nd != null && nd.isValidDate()) {
        final StringBuilder sb = new StringBuilder(40);
        final double t = nd.getLocalTime();

        switch (format) {

            case FORMAT_DATE_TIME:
            case FORMAT_DATE :
            case FORMAT_LOCAL_DATE_TIME:
                // EEE MMM dd yyyy
                sb.append(weekDays[weekDay(t)])
                        .append(' ')
                        .append(months[monthFromTime(t)])
                        .append(' ');
                zeroPad(sb, dayFromTime(t), 2);
                sb.append(' ');
                zeroPad(sb, yearFromTime(t), 4);
                if (format == FORMAT_DATE) {
                    break;
                }
                sb.append(' ');

            case FORMAT_TIME:
                final TimeZone tz = nd.getTimeZone();
                final double utcTime = nd.getTime();
                int offset = tz.getOffset((long) utcTime) / 60000;
                final boolean inDaylightTime = offset != tz.getRawOffset() / 60000;
                // Convert minutes to HHmm timezone offset
                offset = (offset / 60) * 100 + offset % 60;

                // HH:mm:ss GMT+HHmm
                zeroPad(sb, hourFromTime(t), 2);
                sb.append(':');
                zeroPad(sb, minFromTime(t), 2);
                sb.append(':');
                zeroPad(sb, secFromTime(t), 2);
                sb.append(" GMT")
                        .append(offset < 0 ? '-' : '+');
                zeroPad(sb, Math.abs(offset), 4);
                sb.append(" (")
                        .append(tz.getDisplayName(inDaylightTime, TimeZone.SHORT, Locale.US))
                        .append(')');
                break;

            case FORMAT_LOCAL_DATE:
                // yyyy-MM-dd
                zeroPad(sb, yearFromTime(t), 4);
                sb.append('-');
                zeroPad(sb, monthFromTime(t) + 1, 2);
                sb.append('-');
                zeroPad(sb, dayFromTime(t), 2);
                break;

            case FORMAT_LOCAL_TIME:
                // HH:mm:ss
                zeroPad(sb, hourFromTime(t), 2);
                sb.append(':');
                zeroPad(sb, minFromTime(t), 2);
                sb.append(':');
                zeroPad(sb, secFromTime(t), 2);
                break;

            default:
                throw new IllegalArgumentException("format: " + format);
        }

        return sb.toString();
    }

    return INVALID_DATE;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:76,代码来源:NativeDate.java

示例14: getOffset

import java.util.TimeZone; //导入方法依赖的package包/类
/**
 * Gets the offset from UT for the given date in the given time zone, 
 * taking into account daylight savings.
 * 
 * <p>
 * Equivalent of TimeZone.getOffset(date) in JDK 1.4, but Quartz is trying
 * to support JDK 1.3.
 * </p>
 * 
 * @param date the date (in milliseconds) that is the base for the offset
 * @param tz the time-zone to calculate to offset to
 * @return the offset
 * @deprecated use TimeZone.getOffset(date)
 */
public static int getOffset(long date, TimeZone tz) {
    
    if (tz.inDaylightTime(new Date(date))) {
        return tz.getRawOffset() + getDSTSavings(tz);
    }
    
    return tz.getRawOffset();
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:23,代码来源:TriggerUtils.java


注:本文中的java.util.TimeZone.getRawOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。