Example usage for java.text SimpleDateFormat setTimeZone

List of usage examples for java.text SimpleDateFormat setTimeZone

Introduction

In this page you can find the example usage for java.text SimpleDateFormat setTimeZone.

Prototype

public void setTimeZone(TimeZone zone) 

Source Link

Document

Sets the time zone for the calendar of this DateFormat object.

Usage

From source file:com.jaspersoft.jasperserver.war.tags.FormatDateTag.java

public int doStartTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    WebApplicationContext applicationContext = RequestContextUtils.getWebApplicationContext(request);

    Locale locale = RequestContextUtils.getLocale(request);
    TimeZone timezone = JasperServerUtil.getTimezone(request);

    String formattingPattern = getFormattingPattern(applicationContext, locale);
    SimpleDateFormat format = new SimpleDateFormat(formattingPattern, locale);
    format.setTimeZone(timezone);

    String formattedValue = format.format(getValue());

    try {/* w  ww.  j a v  a 2  s .  co  m*/
        //TODO html escaping?
        pageContext.getOut().write(formattedValue);
    } catch (IOException e) {
        log.error(e);
        throw new JspException(e);
    }

    return SKIP_BODY;
}

From source file:com.persistent.cloudninja.scheduler.TenantBlobSizeProcessor.java

/** 
 * Calculates the blob sizes of private and public container.
 * /*from w  ww . j  a v  a 2s.  c  o  m*/
 */
@Override
public boolean execute() {
    boolean retVal = true;
    String tenantId = null;
    long blobSize = 0;
    try {
        LOGGER.debug("In Processor");
        TenantBlobSizeQueue queue = (TenantBlobSizeQueue) getWorkQueue();
        tenantId = queue.dequeue(SchedulerSettings.MessageVisibilityTimeout);
        if (tenantId == null) {
            retVal = false;
            LOGGER.debug("Processor : msg is null");
        } else {
            StopWatch watch = new StopWatch();
            watch.start();
            //get the size of blobs in private container.
            blobSize = storageUtility.getContainerSize("tntp-" + tenantId.toLowerCase());
            //get the size of blobs in public container.
            blobSize = blobSize + storageUtility.getContainerSize("tnts-" + tenantId.toLowerCase());
            LOGGER.debug("Processor : msg is " + tenantId);
            MeteringEntity metering = new MeteringEntity();
            metering.setTenantId(tenantId);

            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            String date = dateFormat.format(calendar.getTime());
            metering.setSnapshotTime(dateFormat.parse(date));
            //set the calculated size
            blobSize = blobSize / 1024;
            metering.setBlobStoreUsage(blobSize);
            meteringDao.add(metering);
            LOGGER.info("Processor : blobSize is " + blobSize);
            watch.stop();
            taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                    "ProcessMeteringBlobSizes", "Measured " + blobSize + " kb for tenant " + tenantId);
        }
    } catch (Exception e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:fxts.stations.trader.ui.dialogs.ADatePage.java

/**
 * Returns begining date//from  w  w w.j  av  a 2s. c  o m
 *
 * @return
 */
public String getBeginDate() {
    Calendar instance = Calendar.getInstance();
    instance.setTime(mCalendarComboBegin.getDate());
    boolean date = instance.get(Calendar.DATE) == Calendar.getInstance().get(Calendar.DATE);
    boolean month = instance.get(Calendar.MONTH) == Calendar.getInstance().get(Calendar.MONTH);
    boolean year = instance.get(Calendar.YEAR) == Calendar.getInstance().get(Calendar.YEAR);
    if (date && month && year) {
        TradingSessionStatus tss = TradingServerSession.getInstance().getTradingSessionStatus();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone(tss.getFXCMServerTimeZoneName()));
        String etd = TradingServerSession.getInstance().getParameterValue("END_TRADING_DAY");
        String now = sdf.format(new Date());
        if (now.compareTo(etd) > 0) {
            instance.roll(Calendar.DATE, true);
        }
        return mDateFormat.format(instance.getTime());
    } else {
        return mDateFormat.format(mCalendarComboBegin.getDate());
    }
}

From source file:net.networksaremadeofstring.cyllell.Authentication.java

private String GetTimeStamp() {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.UK);
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    return sdf.format(new Date());
}

From source file:com.ichi2.libanki.Utils.java

public static void printDate(String name, double date) {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    cal.setTimeInMillis((long) date * 1000);
    Timber.d("Value of %s: %s", name, cal.getTime().toGMTString());
}

From source file:com.persistent.cloudninja.scheduler.TenantDBSizeProcessor.java

/** 
 * Calculates DB size of tenant DB.//from   www . j a  v  a2 s .c om
 */
@Override
public boolean execute() {

    boolean retVal = true;
    String tenantId = null;
    try {

        LOGGER.debug("In Processor");
        long dbSize = 0;
        TenantDBSizeQueue queue = (TenantDBSizeQueue) getWorkQueue();
        tenantId = queue.dequeue(SchedulerSettings.MessageVisibilityTimeout);
        if (tenantId == null) {
            retVal = false;
            LOGGER.debug("Processor : msg is null");
        } else {
            StopWatch watch = new StopWatch();
            watch.start();
            LOGGER.debug("Processor : msg is " + tenantId);
            dbSize = partitionStatsAndBWUsageDao.getDBSize(tenantId);
            MeteringEntity metering = new MeteringEntity();
            metering.setTenantId(tenantId);

            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            String date = dateFormat.format(calendar.getTime());
            metering.setSnapshotTime(dateFormat.parse(date));

            metering.setDatabaseSize(dbSize);
            meteringDao.add(metering);
            LOGGER.info("Processor : dbSize is " + dbSize);
            watch.stop();
            taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                    "ProcessMeteringTenantDatabaseSize",
                    "Measured " + dbSize + " for tenant " + tenantId + " database");
        }
    } catch (StorageException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    } catch (ParseException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:com.xeiam.xchange.bitstamp.BitstampAdapterTest.java

@Test
public void testTickerAdapter() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = BitstampAdapterTest.class.getResourceAsStream("/marketdata/example-ticker-data.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    BitstampTicker bitstampTicker = mapper.readValue(is, BitstampTicker.class);

    Ticker ticker = BitstampAdapters.adaptTicker(bitstampTicker, "BTC", "USD");

    assertThat(ticker.getLast()).isEqualTo(MoneyUtils.parse("USD 134.89"));
    assertThat(ticker.getBid()).isEqualTo(MoneyUtils.parse("USD 134.89"));
    assertThat(ticker.getAsk()).isEqualTo(MoneyUtils.parse("USD 134.92"));
    assertThat(ticker.getVolume()).isEqualTo(new BigDecimal("21982.44926674"));
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    f.setTimeZone(TimeZone.getTimeZone("UTC"));
    String dateString = f.format(ticker.getTimestamp());
    assertThat(dateString).isEqualTo("2013-10-14 21:45:33");
}

From source file:com.xeiam.xchange.bitstamp.BitstampAdapterTest.java

@Test
public void testOrderBookAdapter() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = BitstampAdapterTest.class.getResourceAsStream("/marketdata/example-full-depth-data.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    BitstampOrderBook bitstampOrderBook = mapper.readValue(is, BitstampOrderBook.class);

    OrderBook orderBook = BitstampAdapters.adaptOrders(bitstampOrderBook, "BTC", "USD");
    assertThat(orderBook.getBids().size()).isEqualTo(1281);

    // verify all fields filled
    assertThat(orderBook.getBids().get(0).getLimitPrice().getAmount()).isEqualTo(new BigDecimal("123.09"));
    assertThat(orderBook.getBids().get(0).getType()).isEqualTo(OrderType.BID);
    assertThat(orderBook.getBids().get(0).getTradableAmount()).isEqualTo(new BigDecimal("0.16248274"));
    assertThat(orderBook.getBids().get(0).getTradableIdentifier()).isEqualTo("BTC");
    assertThat(orderBook.getBids().get(0).getTransactionCurrency()).isEqualTo("USD");
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    f.setTimeZone(TimeZone.getTimeZone("UTC"));
    String dateString = f.format(orderBook.getTimeStamp());
    assertThat(dateString).isEqualTo("2013-09-10 12:31:44");
}

From source file:com.clustercontrol.notify.util.NotifyUtil.java

/**
 * ?????/*from   w  ww .  j a  v a 2  s. com*/
 * @param outputInfo 
 * @param notifyInfo 
 * @return ??
 */
public static Map<String, String> createParameter(OutputBasicInfo outputInfo, NotifyInfo notifyInfo) {
    Map<String, String> param = null;
    SimpleDateFormat sdf = null;
    param = new HashMap<String, String>();

    if (outputInfo != null) {

        // 
        Locale locale = getNotifyLocale();

        /**  */
        String subjectDateFormat = HinemosPropertyUtil.getHinemosPropertyStr("notify.date.format",
                SUBJECT_DATE_FORMAT_DEFAULT);
        if (log.isDebugEnabled()) {
            log.debug("TextReplacer.static SUBJECT_DATE_FORMAT = " + subjectDateFormat);
        }

        sdf = new SimpleDateFormat(subjectDateFormat);
        sdf.setTimeZone(HinemosTime.getTimeZone());

        param.put(_KEY_PRIORITY_NUM, String.valueOf(outputInfo.getPriority()));
        if (Messages.getString(PriorityConstant.typeToMessageCode(outputInfo.getPriority()), locale) != null) {
            param.put(_KEY_PRIORITY,
                    Messages.getString(PriorityConstant.typeToMessageCode(outputInfo.getPriority()), locale));
        } else {
            param.put(_KEY_PRIORITY, null);
        }
        if (Messages.getString(PriorityConstant.typeToMessageCode(outputInfo.getPriority()),
                Locale.JAPANESE) != null) {
            param.put(_KEY_PRIORITY_JP, Messages
                    .getString(PriorityConstant.typeToMessageCode(outputInfo.getPriority()), Locale.JAPANESE));
        } else {
            param.put(_KEY_PRIORITY_JP, null);
        }
        if (Messages.getString(PriorityConstant.typeToMessageCode(outputInfo.getPriority()),
                Locale.ENGLISH) != null) {
            param.put(_KEY_PRIORITY_EN, Messages
                    .getString(PriorityConstant.typeToMessageCode(outputInfo.getPriority()), Locale.ENGLISH));
        } else {
            param.put(_KEY_PRIORITY_EN, null);
        }

        String pluginId = outputInfo.getPluginId();
        param.put(_KEY_PLUGIN_ID, pluginId);
        param.put(_KEY_PLUGIN_NAME,
                Messages.getString(HinemosModuleConstant.nameToMessageCode(pluginId), locale));
        String monitorId = outputInfo.getMonitorId();
        param.put(_KEY_MONITOR_ID, outputInfo.getMonitorId());
        if (monitorId != null && pluginId != null && pluginId.startsWith("MON_")) {
            MonitorSettingControllerBean controller = new MonitorSettingControllerBean();
            try {
                MonitorInfo monitorInfo = controller.getMonitor(monitorId);
                param.put(_KEY_MONITOR_DESCRIPTION, monitorInfo.getDescription());
                param.put(_KEY_CALENDAR_ID, monitorInfo.getCalendarId());
                param.put(_KEY_MONITOR_OWNER_ROLE_ID, monitorInfo.getOwnerRoleId());
            } catch (MonitorNotFound e) {
                log.debug("createParameter() : monitor not found. " + e.getMessage());
            } catch (HinemosUnknown e) {
                log.debug("createParameter() : HinemosUnknown. " + e.getMessage());
            } catch (InvalidRole e) {
                log.debug("createParameter() : InvalidRole. " + e.getMessage());
            }
        } else {
            param.put(_KEY_MONITOR_DESCRIPTION, "");
            param.put(_KEY_CALENDAR_ID, "");
            param.put(_KEY_MONITOR_OWNER_ROLE_ID, "");
        }
        param.put(_KEY_MONITOR_DETAIL_ID, outputInfo.getSubKey());

        param.put(_KEY_FACILITY_ID, outputInfo.getFacilityId());
        param.put(_KEY_SCOPE, HinemosMessage.replace(outputInfo.getScopeText(), locale));

        if (outputInfo.getGenerationDate() != null) {
            param.put(_KEY_GENERATION_DATE, sdf.format(outputInfo.getGenerationDate()));
        } else {
            param.put(_KEY_GENERATION_DATE, null);
        }
        param.put(_KEY_APPLICATION, HinemosMessage.replace(outputInfo.getApplication(), locale));
        param.put(_KEY_MESSAGE, HinemosMessage.replace(outputInfo.getMessage(), locale));
        param.put(_KEY_ORG_MESSAGE, HinemosMessage.replace(outputInfo.getMessageOrg(), locale));

        List<String> jobFacilityIdList = outputInfo.getJobFacilityId();
        List<String> jobMessageList = outputInfo.getJobMessage();

        if (jobFacilityIdList != null) {
            for (int i = 0; i < jobFacilityIdList.size(); ++i) {
                String key = _KEY_JOB_MESSAGE + jobFacilityIdList.get(i);
                String value = HinemosMessage.replace(jobMessageList.get(i), locale);
                param.put(key, value);
                log.debug("NotifyUtil.createParameter  >>> param.put = : " + key + "  value = " + value);
            }

        }

        if (outputInfo.getFacilityId() != null) {
            try {
                RepositoryControllerBean repositoryCtrl = new RepositoryControllerBean();
                FacilityInfo facility = repositoryCtrl.getFacilityEntityByPK(outputInfo.getFacilityId());
                param.put(_KEY_FACILITY_NAME, HinemosMessage.replace(facility.getFacilityName(), locale));
                if (FacilityUtil.isNode(facility)) {
                    NodeInfo nodeInfo = repositoryCtrl.getNode(outputInfo.getFacilityId());
                    Map<String, String> variable = RepositoryUtil.createNodeParameter(nodeInfo);
                    param.putAll(variable);
                }
            } catch (FacilityNotFound e) {
                log.debug("createParameter() : facility not found. " + e.getMessage());
            } catch (InvalidRole e) {
                log.debug("createParameter() : InvalidRole. " + e.getMessage());
            } catch (HinemosUnknown e) {
                log.debug("createParameter() : HinemosUnknown. " + e.getMessage());
            } catch (Exception e) {
                log.warn("facility not found. (" + outputInfo.getFacilityId() + ") : "
                        + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
            }
        }

        if (outputInfo.getJobApprovalText() != null) {
            param.put(_KEY_JOB_APPROVAL_TEXT, HinemosMessage.replace(outputInfo.getJobApprovalText()));
            log.info("_KEY_JOB_APPROVAL_TEXT" + outputInfo.getJobApprovalText());
        }
        if (outputInfo.getJobApprovalText() != null) {
            param.put(_KEY_JOB_APPROVAL_MAIL, HinemosMessage.replace(outputInfo.getJobApprovalMail()));
            log.info("_KEY_JOB_APPROVAL_MAIL" + outputInfo.getJobApprovalMail());
        }
    }

    if (notifyInfo != null) {
        param.put(_KEY_NOTIFY_ID, String.valueOf(notifyInfo.getNotifyId()));
        param.put(_KEY_NOTIFY_DESCRIPTION, notifyInfo.getDescription());
    }

    if (log.isTraceEnabled()) {
        for (Map.Entry<String, String> entry : param.entrySet()) {
            log.trace("createParameter() : param[" + entry.getKey() + "]=" + entry.getValue());
        }
    }

    return param;
}

From source file:com.mercandalli.android.apps.files.common.dialog.DialogCreateArticle.java

public DialogCreateArticle(final Activity activity, final IListener listener) {
    super(activity);
    this.mActivity = activity;

    this.setContentView(R.layout.dialog_create_article);
    this.setTitle("Create Article");
    this.setCancelable(true);

    this.article_title_1 = (EditText) this.findViewById(R.id.title);
    this.article_content_1 = (EditText) this.findViewById(R.id.content);

    this.findViewById(R.id.request).setOnClickListener(new View.OnClickListener() {
        @Override/*from w  w w . j  a v a  2  s.c om*/
        public void onClick(View v) {

            SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
            dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"));

            String nowAsISO = dateFormatGmt.format(new Date());

            JSONObject json = new JSONObject();
            try {
                json.put("type", "article");
                json.put("date_creation", nowAsISO);
                json.put("article_title_1", article_title_1.getText().toString());
                json.put("article_content_1", article_content_1.getText().toString());

                SimpleDateFormat dateFormatGmtTZ = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm'Z'", Locale.US);
                dateFormatGmtTZ.setTimeZone(TimeZone.getTimeZone("UTC"));
                nowAsISO = dateFormatGmtTZ.format(new Date());

                List<StringPair> parameters = new ArrayList<>();
                parameters.add(new StringPair("content", json.toString()));
                parameters.add(new StringPair("name", "ARTICLE_" + nowAsISO));
                new TaskPost(mActivity, Constants.URL_DOMAIN + Config.ROUTE_FILE, new IPostExecuteListener() {
                    @Override
                    public void onPostExecute(JSONObject json, String body) {
                        if (listener != null) {
                            listener.execute();
                        }
                    }
                }, parameters, "text/html; charset=utf-8").execute();
            } catch (JSONException e) {
                Log.e(TAG, "DialogCreateArticle: failed to convert Json", e);
            }

            DialogCreateArticle.this.dismiss();
        }
    });

    DialogCreateArticle.this.show();
}