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:no.met.jtimeseries.netcdf.plot.MultiPlotProvider.java

public XYPlot getPlot(List<NumberPhenomenon> dataList) {
    DateAxis domainAxis = new DateAxis("T", TimeZone.getTimeZone("UTC"), Locale.getDefault());
    domainAxis.setRange(dataList.get(0).getStartTime(), dataList.get(0).getEndTime());

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis);

    for (PlotProvider provider : subProviders) {

        List<String> variables = dataForProviders.get(provider);
        if (variables == null)
            plot.add(provider.getPlot(dataList));
        else/*from  ww  w.  j  a  v a 2  s.  co m*/
            plot.add(provider.getPlot(extractNumberPhenomena(variables, dataList)));
    }

    return plot;
}

From source file:com.logsniffer.fields.filter.support.TimestampConvertFilter.java

@Override
protected Date transform(final String sourceValue) {
    try {/*from  ww  w  . jav  a 2  s . c o m*/
        if (parsedPattern == null) {
            if (locale != null) {
                parsedPattern = new SimpleDateFormat(pattern, locale);
            } else {
                parsedPattern = new SimpleDateFormat(pattern);
            }
            if (StringUtils.isNotBlank(timeZone)) {
                parsedPattern.setTimeZone(TimeZone.getTimeZone(timeZone));
            }
        }
        return parsedPattern.parse(sourceValue);
    } catch (ParseException | IllegalArgumentException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to parse date in format '" + pattern + "' from string: " + sourceValue, e);
        }
    }
    return null;
}

From source file:it.jugpadova.blol.FeedsBoTest.java

public void testConvertDateAndTimeBrazil() throws ParseException {
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    df.setTimeZone(TimeZone.getTimeZone("America/Sao_Paulo"));
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    net.fortuna.ical4j.model.TimeZone tz = registry.getTimeZone("America/Sao_Paulo");
    Date d = df.parse("18/09/2009");
    net.fortuna.ical4j.model.Date cd1 = feedsBo.convertDateAndTime(d, "12:00 AM", tz);
    assertEquals("20090918T120000", cd1.toString());
    net.fortuna.ical4j.model.Date cd2 = feedsBo.convertDateAndTime(d, "05:00 PM", tz);
    assertEquals("20090918T170000", cd2.toString());
}

From source file:org.matsim.contrib.dvrp.util.chart.ScheduleCharts.java

public static JFreeChart chartSchedule(Collection<? extends Vehicle> vehicles,
        DescriptionCreator descriptionCreator, PaintSelector paintSelector) {
    // data//  w  ww .j av a2 s  .com
    TaskSeriesCollection dataset = createScheduleDataset(vehicles, descriptionCreator);
    XYTaskDataset xyTaskDataset = new XYTaskDataset(dataset);

    // chart
    JFreeChart chart = ChartFactory.createXYBarChart("Schedules", "Time", false, "Vehicles", xyTaskDataset,
            PlotOrientation.HORIZONTAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();

    // Y axis
    String[] series = new String[vehicles.size()];
    int i = 0;
    for (Vehicle v : vehicles) {
        series[i++] = v.getId().toString();
    }

    SymbolAxis symbolAxis = new SymbolAxis("Vehicles", series);
    symbolAxis.setGridBandsVisible(false);
    plot.setDomainAxis(symbolAxis);

    // X axis
    plot.setRangeAxis(new DateAxis("Time", TimeZone.getTimeZone("GMT"), Locale.getDefault()));

    // Renderer
    XYBarRenderer xyBarRenderer = new ChartTaskRenderer(dataset, paintSelector);
    xyBarRenderer.setUseYInterval(true);
    plot.setRenderer(xyBarRenderer);

    return chart;
}

From source file:com.qtplaf.library.util.Calendar.java

/**
 * Returns a GTM calendar.//ww  w . j  av a  2s  . c  o  m
 *
 * @param year The year
 * @param month The month, from 1 to 12
 * @param day The day
 * @param hour The hour
 * @param minute The minute
 * @param second The second
 * @param millis The millisecond
 * @return The calendar.
 */
public static Calendar getGTMCalendar(int year, int month, int day, int hour, int minute, int second,
        int millis) {
    return getCalendar(TimeZone.getTimeZone("GTM"), year, month, day, hour, minute, second, millis);
}

From source file:com.boundary.sdk.event.esper.QueryListTest.java

@Test
public void test() {
    Query query1 = queryList.getQueries().get(0);
    Builder build1 = new Calendar.Builder();
    build1.setTimeZone(TimeZone.getTimeZone("GMT"));
    build1.setDate(2015, 0, 27);//from  ww w.j  a v a2  s  .c  om
    build1.setTimeOfDay(0, 0, 0, 0);
    Calendar cal1 = build1.build();
    assertEquals("check query 1 name", "red", query1.getName());
    assertEquals("check query 1 create", cal1.getTime(), query1.getCreated());
    assertEquals("check query 1 modified", cal1.getTime(), query1.getModified());
    assertEquals("check query 1 enabled", true, query1.isEnabled());
    assertEquals("check query 1 description", "Red description", query1.getDescription());
    assertEquals("check query 1 query", "select * from Red where name = 'ONE' and property = 2",
            query1.getQuery());

    Query query2 = queryList.getQueries().get(1);
    Builder build2 = new Calendar.Builder();
    build2.setTimeZone(TimeZone.getTimeZone("GMT"));
    build2.setDate(1992, 5, 20);
    build2.setTimeOfDay(0, 0, 0, 0);
    Calendar cal2 = build2.build();
    assertEquals("check query 2 name", "blue", query2.getName());
    assertEquals("check query 2 create", cal2.getTime(), query2.getCreated());
    assertEquals("check query 2 modified", cal2.getTime(), query2.getCreated());
    assertEquals("check query 2 enabled", false, query2.isEnabled());
    assertEquals("check query 2 description", "Blue description", query2.getDescription());
    assertEquals("check query 2 query", "select * from Blue where name = 'ONE' and property = 2",
            query2.getQuery());

    Query query3 = queryList.getQueries().get(2);
    Builder build3 = new Calendar.Builder();
    build3.setTimeZone(TimeZone.getTimeZone("GMT"));
    build3.setDate(2000, 11, 10);
    build3.setTimeOfDay(0, 0, 0, 0);
    Calendar cal3 = build3.build();
    assertEquals("check query 3 name", "green", query3.getName());
    assertEquals("check query 3 create", cal3.getTime(), query3.getCreated());
    assertEquals("check query 3 enabled", true, query3.isEnabled());
    assertEquals("check query 3 description", "Green description", query3.getDescription());
    assertEquals("check query 3 query", "select * from Green where name = 'ONE' and property = 2",
            query3.getQuery());

}

From source file:com.oneops.antenna.senders.generic.XMPPMsgService.java

@PostConstruct
public void init() {
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    xmpp = metrics.meter(name(ANTENNA, "xmpp.count"));
    xmppErr = metrics.meter(name(ANTENNA, "xmpp.error"));
}

From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionRepresentation.java

/**
 * Instantiates a new step execution representation.
 *
 * @param stepExecution the step execution
 * @param timeZone      the time zone//  ww  w.j  a  v a  2  s  .co m
 */
public StepExecutionRepresentation(StepExecution stepExecution, TimeZone timeZone) {

    this.setStepExecutionDetailsRepresentation(new StepExecutionDetailsRepresentation(stepExecution));
    this.id = stepExecution.getId();
    this.name = stepExecution.getStepName();
    this.jobName = stepExecution.getJobExecution() == null
            || stepExecution.getJobExecution().getJobInstance() == null ? "?"
                    : stepExecution.getJobExecution().getJobInstance().getJobName();
    this.jobExecutionId = stepExecution.getJobExecutionId();
    // Duration is always in GMT
    durationFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    timeFormat.setTimeZone(timeZone);
    dateFormat.setTimeZone(timeZone);
    if (stepExecution.getStartTime() != null) {
        this.startDate = dateFormat.format(stepExecution.getStartTime());
        this.startTime = timeFormat.format(stepExecution.getStartTime());
        Date endTime = stepExecution.getEndTime() != null ? stepExecution.getEndTime() : new Date();

        this.durationMillis = endTime.getTime() - stepExecution.getStartTime().getTime();
        this.duration = durationFormat.format(new Date(durationMillis));
    }
    if (stepExecution.getEndTime() != null) {
        this.endTime = timeFormat.format(stepExecution.getEndTime());
    }

}

From source file:com.telefonica.euro_iaas.sdc.util.MixlibAuthenticationDigesterImpl.java

/**
 * {@inheritDoc}// w  ww.jav  a 2s  .c  o m
 */
public Map<String, String> digest(String method, String path, String body, Date timestamp, String id,
        String pkUrl) {
    try {
        DateFormat df = new SimpleDateFormat(propertiesProvider.getProperty(CHEF_DATE_FORMAT));
        df.setTimeZone(TimeZone.getTimeZone(propertiesProvider.getProperty(CHEF_TIME_ZONE)));

        Map<String, String> headers = new HashMap<String, String>();
        headers.put(CONTENT_HASH_HEADER, getHash(body));
        headers.put(TIMESTAMP_HEADER, df.format(timestamp));
        headers.put(USER_HEADER, id);
        headers.put(SIGN_VERSION_HEADER, SIGN_VERSION_VALUE);

        String digest = MessageFormat.format(BODY_TEMPLATE, method.toUpperCase(), getHash(path), getHash(body),
                df.format(timestamp), id);
        digest = signer.sign(digest, new File(pkUrl));
        Integer length;
        Integer iteration = 1;
        while (!digest.isEmpty()) {
            length = digest.length() >= 60 ? 60 : digest.length();
            headers.put(AUTH_HEADER_PREFIX + iteration, digest.substring(0, length));
            digest = digest.substring(length);
            iteration = iteration + 1;
        }
        return headers;
    } catch (Exception e) {
        throw new SdcRuntimeException();
    }
}

From source file:edu.harvard.iq.safe.lockss.impl.DaemonStatusDataUtil.java

public static String getStdFrmtdTime(Date date, String timestampPattern, String timezoneId) {
    return FastDateFormat.getInstance(timestampPattern, TimeZone.getTimeZone(timezoneId)).format(date);
}