Example usage for java.util TimeZone getTimeZone

List of usage examples for java.util TimeZone getTimeZone

Introduction

In this page you can find the example usage for java.util TimeZone getTimeZone.

Prototype

public static TimeZone getTimeZone(ZoneId zoneId) 

Source Link

Document

Gets the TimeZone for the given zoneId .

Usage

From source file:iddb.web.viewbean.PenaltyViewBean.java

@Override
public String toString() {
    if (this.blank)
        return MessageResource.getMessage("banned");

    StringBuilder s = new StringBuilder();
    DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    format.setTimeZone(TimeZone.getTimeZone("GMT-3"));

    s.append("Baneado el ").append(format.format(this.getCreated()));
    if (this.getDuration() > 0) {
        DateFormat format2 = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        format2.setTimeZone(TimeZone.getTimeZone("GMT-3"));
        s.append(" hasta ").append(format2.format(this.getExpires()));
    }/*from www . j av a2 s  .  com*/
    if (StringUtils.isNotEmpty(this.getReason())) {
        s.append(". Motivo: ").append(this.getReason());
    } else {
        s.append(". No indica motivo.");
    }
    if (StringUtils.isNotEmpty(this.getAdmin())) {
        s.append(" (").append(getAdmin()).append(")");
    }
    return s.toString();
}

From source file:hello.Scraper.java

@Transformer(inputChannel = "channel3", outputChannel = "channel4")
public DumpEntry convert(Element payload) throws ParseException {
    String dateStr = payload.ownText().substring(0, 19);

    DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    format.setTimeZone(TimeZone.getTimeZone("GMT"));

    Date timestamp = format.parse(dateStr);

    Elements list = payload.select("a");
    String id;//from  ww w. j  a  v  a2 s  . c o  m
    String ref;
    if (list.size() > 0) {
        Element a = list.get(0);
        id = a.ownText();
        ref = a.attr("href");
    } else {
        id = "private data";
        ref = null;
    }

    Element span = payload.select("span").get(0);
    String status = span.ownText();

    return new DumpEntry(timestamp, id, ref, status);
}

From source file:android.framework.org.apache.harmony.security_custom.asn1.ASN1GeneralizedTime.java

public void setEncodingContent(BerOutputStream out) {
    SimpleDateFormat sdf = new SimpleDateFormat(GEN_PATTERN);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String temp = sdf.format(out.content);
    // cut off trailing 0s
    int nullId;/*w w  w . ja v a  2 s .  c  o  m*/
    int currLength;
    while (((nullId = temp.lastIndexOf('0', currLength = temp.length() - 1)) != -1) & (nullId == currLength)) {
        temp = temp.substring(0, nullId);
    }
    // deal with point (cut off if it is last char)
    if (temp.charAt(currLength) == '.') {
        temp = temp.substring(0, currLength);
    }

    out.content = (temp + "Z").getBytes(Charsets.UTF_8);
    out.length = ((byte[]) out.content).length;
}

From source file:com.bc.fiduceo.db.Storage.java

private Driver createDriver(BasicDataSource dataSource) {
    // ensure all dates are interpreted as UTC
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    final String dbUrl = dataSource.getUrl().toLowerCase();

    final DriverUtils syDriverUtils = new DriverUtils();
    return syDriverUtils.getDriver(dbUrl);
}

From source file:io.github.sparta.helpers.date.DateUtil.java

/**
 * Get time zones.//from  w ww .j  a v  a2s  .co  m
 * 
 * @return map typezone id and GMT
 */
public static Map<String, String> getFilteredTimeZoneMap() {
    if (timezoneIDMap == null) {
        timezoneIDMap = new LinkedHashMap<String, String>();
        String[] ids = TimeZone.getAvailableIDs();
        for (String id : ids) {
            TimeZone zone = TimeZone.getTimeZone(id);
            int offset = zone.getRawOffset();
            int offsetSecond = offset / CONSTANT_1000;
            int hour = offsetSecond / (CONSTANT_60 * CONSTANT_60);
            int minutes = (offsetSecond % (CONSTANT_60 * CONSTANT_60)) / CONSTANT_60;
            timezoneIDMap.put(TimeZone.getTimeZone(id).getDisplayName(),
                    String.format("(GMT%+d:%02d) %s", hour, minutes, id));
        }
    }
    return timezoneIDMap;
}

From source file:com.lfv.yada.net.server.ServerLogger.java

public synchronized void resume(int h, int m, int s) {
    // Create a calendar
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.set(Calendar.HOUR_OF_DAY, h);
    cal.set(Calendar.MINUTE, m);/*from w  ww  . j  a v a2s. c  om*/
    cal.set(Calendar.SECOND, s);
    resumeTime = cal.getTimeInMillis();
    startTime = System.currentTimeMillis();
    suspendTime = 0;
}

From source file:org.apache.camel.component.hipchat.HipchatConsumer.java

private void processExchangeForUser(String user, Exchange exchange) throws Exception {
    String urlPath = String.format(getMostRecentMessageUrl(), user);
    LOG.debug("Polling HipChat Api " + urlPath + " for new messages at "
            + Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime());
    HttpGet httpGet = new HttpGet(getConfig().hipChatUrl() + urlPath);
    CloseableHttpResponse response = executeGet(httpGet);
    exchange.getIn().setHeader(HipchatConstants.FROM_USER, user);
    processApiResponse(exchange, response);
}

From source file:ch.algotrader.adapter.dc.DCFixMarketDataMessageHandler.java

public void onMessage(MarketDataSnapshotFullRefresh marketData, SessionID sessionID) throws FieldNotFound {

    Symbol symbol = marketData.getSymbol();

    int count = marketData.getGroupCount(NoMDEntries.FIELD);
    for (int i = 1; i <= count; i++) {

        Group group = marketData.getGroup(i, NoMDEntries.FIELD);
        char entryType = group.getChar(MDEntryType.FIELD);
        if (entryType == MDEntryType.BID || entryType == MDEntryType.OFFER) {

            double price = group.getDouble(MDEntryPx.FIELD);
            double size = group.getDouble(MDEntrySize.FIELD);
            Date time = group.getUtcTimeOnly(MDEntryTime.FIELD);

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
            calendar = DateUtils.truncate(calendar, Calendar.DATE);
            Date date = new Date(calendar.getTimeInMillis() + time.getTime());

            String tickerId = symbol.getValue();
            switch (entryType) {
            case MDEntryType.BID:

                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("{} BID {}@{}", symbol.getValue(), size, price);
                }/*from w  w w.  j av  a  2  s . co m*/

                BidVO bidVO = new BidVO(tickerId, FeedType.DC.name(), date, price, (int) size);
                this.serverEngine.sendEvent(bidVO);
                break;
            case MDEntryType.OFFER:

                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("{} ASK {}@{}", symbol.getValue(), size, price);
                }

                AskVO askVO = new AskVO(tickerId, FeedType.DC.name(), date, price, (int) size);

                this.serverEngine.sendEvent(askVO);
                break;
            }
        }
    }
}

From source file:org.shredzone.cilla.admin.TimeZoneBean.java

@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
    try {/*w  w w  .ja  v a  2s .  c  o  m*/
        if (string == null) {
            return null;
        }

        String qstr = string.trim();

        if (qstr.isEmpty()) {
            return null;
        }

        if (timeZoneMap.containsKey(qstr)) {
            return timeZoneMap.get(qstr);
        }

        return timeZoneMap.entrySet().stream().filter(it -> it.getKey().equalsIgnoreCase(qstr))
                .map(it -> it.getValue()).findFirst().orElse(TimeZone.getTimeZone(string));
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new ConverterException(ex);
    }
}

From source file:net.asfun.jangod.lib.filter.DatetimeFilter.java

@Override
public Object filter(Object object, JangodInterpreter interpreter, String... arg) throws InterpretException {
    if (object == null) {
        return object;
    }//from w w w. ja  v  a 2 s.c  om
    if (object instanceof DateTime) { // joda DateTime
        DateTimeFormatter formatter;
        DateTimeFormatter a = DateTimeFormat.forPattern(interpreter.evaluateExpressionAsString(arg[0]));
        if (arg.length == 1) {
            DateTimeFormatter forPattern = a;
            JodaTimeContext jodaTimeContext = JodaTimeContextHolder.getJodaTimeContext();
            if (jodaTimeContext == null) {
                jodaTimeContext = new JodaTimeContext();
            }
            formatter = jodaTimeContext.getFormatter(forPattern);
        } else if (arg.length == 2) {
            formatter = a.withChronology(ISOChronology
                    .getInstance(DateTimeZone.forID(interpreter.evaluateExpressionAsString(arg[1]))));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return formatter.print((DateTime) object);
    } else {
        SimpleDateFormat sdf;
        if (arg.length == 1) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(interpreter.getConfiguration().getTimezone());
        } else if (arg.length == 2) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(TimeZone.getTimeZone(interpreter.evaluateExpressionAsString(arg[1])));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return sdf.format(object);
    }
}