Example usage for java.util Calendar ZONE_OFFSET

List of usage examples for java.util Calendar ZONE_OFFSET

Introduction

In this page you can find the example usage for java.util Calendar ZONE_OFFSET.

Prototype

int ZONE_OFFSET

To view the source code for java.util Calendar ZONE_OFFSET.

Click Source Link

Document

Field number for get and set indicating the raw offset from GMT in milliseconds.

Usage

From source file:Main.java

private static TimeZone guessTimeZone(Calendar c, String country) {
    return TimeUtils.getTimeZone(c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET),
            c.get(Calendar.DST_OFFSET) != 0, c.getTimeInMillis(), country);
}

From source file:Main.java

public static String getGMTTimeString(long millisecond) {
    Calendar cal = Calendar.getInstance();
    int zoneOffsetTime = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
    long millisecondsUTC = millisecond - zoneOffsetTime;
    GMTTimeFormatter.setTimeZone(TimeZone.getDefault());
    String strGMTTime = GMTTimeFormatter.format(millisecondsUTC);
    return strGMTTime;
}

From source file:Main.java

@NonNull
public static synchronized String humanReadableDate(final long date, final boolean isUtc) {
    if (isUtc) {/*from w w  w  .  j ava 2s . co  m*/
        final long offset = -(CALENDAR.get(Calendar.ZONE_OFFSET) + CALENDAR.get(Calendar.DST_OFFSET));
        return sFormat.format(date - offset);
    } else {
        return sFormat.format(date);
    }
}

From source file:org.exoplatform.poll.service.Utils.java

public static Calendar getGreenwichMeanTime() {
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setLenient(false);/*from  www .j  av a 2s. c  om*/
    int gmtoffset = calendar.get(Calendar.DST_OFFSET) + calendar.get(Calendar.ZONE_OFFSET);
    calendar.setTimeInMillis(System.currentTimeMillis() - gmtoffset);
    return calendar;
}

From source file:org.betaconceptframework.astroboa.util.DateUtils.java

public static Calendar clearTimeFromCalendar(Calendar calendar) {
    if (calendar != null) {
        calendar.set(Calendar.HOUR, 0);
        calendar.clear(Calendar.AM_PM); //ALWAYS clear AM_PM before HOUR_OF_DAY
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.clear(Calendar.DST_OFFSET);
        calendar.clear(Calendar.ZONE_OFFSET);
    }/*from w  w w . j  a v a 2 s  .c  om*/

    return calendar;
}

From source file:com.mediaportal.ampdroid.api.JsonUtils.java

public static BasicNameValuePair newPair(String _name, Date _value) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(_value);// w ww  .  j  a v  a2  s  . c o  m
    int offset = (int) ((cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000);

    cal.add(Calendar.MINUTE, offset);
    String dateString = IsoDate.dateToString(cal.getTime(), IsoDate.DATE_TIME);

    return new BasicNameValuePair(_name, dateString);
}

From source file:net.maritimecloud.identityregistry.model.database.CertificateModel.java

@PreRemove
public void preRemove() {
    if (getCertificates() != null) {
        // Dates are converted to UTC before saving into the DB
        Calendar cal = Calendar.getInstance();
        long offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
        Date now = new Date(cal.getTimeInMillis() - offset);
        for (Certificate cert : getCertificates()) {
            // Revoke certificates
            cert.setRevokedAt(now);//  ww w .j av a2 s  .  c  om
            cert.setEnd(now);
            cert.setRevokeReason("cessationofoperation");
            cert.setRevoked(true);
            // Detach certificate from entity - since the model type isn't known, just blank all.
            cert.setOrganization(null);
            cert.setDevice(null);
            cert.setService(null);
            cert.setUser(null);
            cert.setVessel(null);
        }
    }
}

From source file:org.apache.hadoop.hive.ql.udf.UDFSessionTimeZone.java

public Text evaluate() {

    try {//  w  w  w . j a  v a 2  s.  c om
        TimeZone tz = TimeZone.getDefault();
        Calendar calendar = Calendar.getInstance(tz);
        int off = calendar.get(Calendar.ZONE_OFFSET);
        off = off / 3600000;
        String ooo = String.format("%1$+03d", off);
        ooo = ooo + ":00";
        result.set(ooo);
        return result;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

/**
 * This method converts from GMT to local timezone
 * //from   www .j  a va2 s. c  om
 * @param date
 *       date in GMT timezone
 * @return the date in local timezone
 */
public static Date offsetDateFromGMT(final Date date) {
    // Create a calendar - it will default to the current OS timezone.
    final GregorianCalendar gc = new GregorianCalendar();

    // Calculate the total offset from GMT
    final int totalOffset = gc.get(Calendar.ZONE_OFFSET) + gc.get(Calendar.DST_OFFSET);

    // Calculate the time in GMT
    final long localTime = date.getTime() + totalOffset;

    // Create a date using the calculated GMT time
    final Date localDate = new Date(localTime);

    return localDate;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFTz_Offset.java

public Text evaluate(Text timezone) {

    if (timezone == null) {
        return null;
    }/*from  w  w  w  . ja v a 2  s. co m*/
    try {
        String ttt = timezone.toString();
        if (ttt.endsWith("00") && (!ttt.startsWith("GMT"))) {
            ttt = "GMT" + ttt;
        }
        TimeZone tz = TimeZone.getTimeZone(ttt);
        Calendar calendar = Calendar.getInstance(tz);
        int off = calendar.get(Calendar.ZONE_OFFSET);
        off = off / 3600000;
        String ooo = String.format("%1$+03d", off);
        ooo = ooo + ":00";
        result.set(ooo);
        return result;
    } catch (Exception e) {
        return null;
    }
}