Example usage for java.util Calendar DST_OFFSET

List of usage examples for java.util Calendar DST_OFFSET

Introduction

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

Prototype

int DST_OFFSET

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

Click Source Link

Document

Field number for get and set indicating the daylight saving offset in milliseconds.

Usage

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 av a  2 s  . co m

    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);//from w ww  .  j  a va  2  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 a  2 s.c o m*/
            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:Main.java

/**
 * This method converts from GMT to local timezone
 * /*from  ww  w .  j av  a 2 s.c  o  m*/
 * @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.energy_home.jemma.internal.ah.eh.esp.ESPContainersDataUtils.java

public static int addIntermediateItems(Calendar c, long previousTime, long nextTime,
        ContentInstanceItems resultItems, int resolution, int lastAddedItems) {
    List<ContentInstance> resultList = resultItems.getContentInstances();
    long normalizedStartTime = getNormalizedStartTime(c, previousTime, resolution);
    int startDst = c.get(Calendar.DST_OFFSET);
    long normalizedEndTime = getNormalizedEndTime(c, nextTime, resolution);
    //      if (normalizedEndTime-nextTime <= 1000) {
    //         // This hack is necessary to manage some of the hap server approximation errors
    //         normalizedEndTime = getNormalizedEndTime(c, nextTime+1000, resolution);
    //         log.warn("Hap millisecond approximation error");
    //      }/*from w ww .jav a  2  s  . c om*/
    int endDst = c.get(Calendar.DST_OFFSET);

    int itemsToBeAdded = getResultListSize(c, normalizedStartTime, normalizedEndTime, resolution);
    itemsToBeAdded = itemsToBeAdded - 2;
    if (lastAddedItems < 0 && itemsToBeAdded + lastAddedItems >= 0) {
        // This hack is necessary to manage some of the hap server approximation on milliseconds
        itemsToBeAdded = itemsToBeAdded + lastAddedItems;
        log.warn("getNextItemsToAdd negative value compensated");
    }
    int itemsAdded = 0;
    if (itemsToBeAdded < 0) {
        log.warn("getNextItemsToAdd returned a negative value: " + itemsToBeAdded);
        itemsAdded = itemsToBeAdded;
    } else if (itemsToBeAdded > 0) {
        if (resolution == ESPService.HOUR_RESOLUTION && endDst > startDst) {
            normalizedStartTime += 1;
            while (itemsAdded < itemsToBeAdded) {
                normalizedStartTime += ONE_HOUR_IN_MILLISEC;
                c.setTimeInMillis(normalizedStartTime);
                startDst = c.get(Calendar.DST_OFFSET);
                if (startDst == endDst) {
                    resultList.add(getDefaultContentInstance(AHContainerAddress
                            .getAddressFromUrl(resultItems.getAddressedId()).getContainerName(),
                            normalizedStartTime));
                    itemsAdded++;
                    break;
                } else {
                    resultList.add(null);
                    itemsAdded++;
                }
            }
        }
        while (itemsAdded < itemsToBeAdded) {
            resultList.add(null);
            itemsAdded++;
        }
    }
    return itemsAdded;
}

From source file:org.appverse.web.framework.backend.frontfacade.json.controllers.JSONDateSerializer.java

@Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    long millis = date.getTime();
    Date currentDate = new Date();
    Calendar cal = new GregorianCalendar();
    cal.setTime(currentDate);/*w ww  . j  a v a2s.c  o m*/
    int offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
    gen.writeNumber(millis + offset);
}

From source file:CalendarDemo.java

public void format() {

    // Tell the calendar what date/time to format
    calendar.setTime(timeNow);//from   ww  w  .jav a2 s. com

    // print out most of the known fields
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:com.balch.mocktrade.finance.QuoteGoogleFinance.java

@Override
public Date getLastTradeTime() {
    TimeZone ny_tz = TimeZone.getTimeZone("America/New_York");
    Calendar ny_cal = Calendar.getInstance(ny_tz);
    int offset_mins = (ny_cal.get(Calendar.ZONE_OFFSET) + ny_cal.get(Calendar.DST_OFFSET)) / 60000;

    String dateStr = this.data.get(LastTradeTime);
    dateStr = dateStr.replace("Z", String.format("%s%02d:%02d", (offset_mins >= 0) ? "+" : "-",
            Math.abs(offset_mins / 60), Math.abs(offset_mins % 60)));
    try {//from  ww  w.  j  a v  a 2  s  . c o  m
        return ISO8601DateTime.toDate(dateStr);
    } catch (ParseException e) {
        Log.e(TAG, "Error parsing date:" + dateStr, e);
        throw new RuntimeException(e);
    }
}

From source file:org.openhab.binding.astro.internal.config.AstroThingConfig.java

/**
 * {@inheritDoc}/*from www.  ja  v a  2s .com*/
 */
@Override
public String toString() {
    TimeZone tz = TimeZone.getDefault();
    StringBuilder tzInfo = new StringBuilder();
    tzInfo.append(tz.getID());
    tzInfo.append(" (").append(tz.getDisplayName(false, TimeZone.SHORT)).append(" ")
            .append(new SimpleDateFormat("Z").format(Calendar.getInstance().getTime()));
    tzInfo.append(")");
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("thing", thingUid)
            .append("geolocation", geolocation).append("interval", interval)
            .append("systemTimezone", tzInfo.toString())
            .append("daylightSavings", Calendar.getInstance().get(Calendar.DST_OFFSET) != 0).toString();
}

From source file:org.eclipse.smarthome.binding.astro.internal.config.AstroThingConfig.java

@Override
public String toString() {
    TimeZone tz = TimeZone.getDefault();
    StringBuilder tzInfo = new StringBuilder();
    tzInfo.append(tz.getID());//from w  ww .  j av a 2s.  com
    tzInfo.append(" (").append(tz.getDisplayName(false, TimeZone.SHORT)).append(" ")
            .append(new SimpleDateFormat("Z").format(Calendar.getInstance().getTime()));
    tzInfo.append(")");
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("thing", thingUid)
            .append("geolocation", geolocation).append("altitude", altitude).append("interval", interval)
            .append("systemTimezone", tzInfo.toString())
            .append("daylightSavings", Calendar.getInstance().get(Calendar.DST_OFFSET) != 0).toString();
}