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: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 . jav  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:com.auditbucket.registration.repo.neo4j.model.FortressNode.java

public FortressNode(FortressInputBean fortressInputBean, Company ownedBy) {
    this();/*from   w w w  . j  av  a 2  s  .c  o  m*/
    setName(fortressInputBean.getName());
    setSearchActive(fortressInputBean.getSearchActive());
    setCompany(ownedBy);
    if (fortressInputBean.getTimeZone() != null) {
        this.timeZone = fortressInputBean.getTimeZone();
        if (TimeZone.getTimeZone(timeZone) == null)
            throw new IllegalArgumentException(fortressInputBean.getTimeZone()
                    + " is not a valid TimeZone. If you don't know a timezone to set, leave this null and the system default will be used.");
    }
    if (fortressInputBean.getLanguageTag() != null)
        this.languageTag = fortressInputBean.getLanguageTag();
    else
        getLanguageTag();

    fortressKey = UUID.randomUUID();
}

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

public static <T extends Task> JFreeChart chartSchedule(List<? extends Vehicle> vehicles,
        DescriptionCreator<T> descriptionCreator, PaintSelector<T> paintSelector) {
    // data/*w ww .j  a v  a 2s . co m*/
    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()];
    for (int i = 0; i < series.length; i++) {
        series[i] = vehicles.get(i).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<T>(dataset, paintSelector);
    xyBarRenderer.setUseYInterval(true);
    plot.setRenderer(xyBarRenderer);

    return chart;
}

From source file:com.aliyun.odps.ship.common.RecordConverter.java

public RecordConverter(TableSchema schema, String nullTag, String dateFormat, String tz, String charset)
        throws UnsupportedEncodingException {

    this.schema = schema;
    this.nullTag = nullTag;

    if (dateFormat == null) {
        this.dateFormatter = new SimpleDateFormat(Constants.DEFAULT_DATE_FORMAT_PATTERN);
    } else {//from   www .  j ava 2s.c  om
        dateFormatter = new SimpleDateFormat(dateFormat);
    }
    dateFormatter.setLenient(false);
    if (tz != null) {
        TimeZone t = TimeZone.getTimeZone(tz);
        if (!tz.equalsIgnoreCase("GMT") && t.getID().equals("GMT")) {
            System.err.println(
                    Constants.WARNING_INDICATOR + "possible invalid time zone: " + tz + ", fall back to GMT");
        }
        dateFormatter.setTimeZone(t);
    }

    doubleFormat = new DecimalFormat();
    doubleFormat.setMinimumFractionDigits(0);
    doubleFormat.setMaximumFractionDigits(20);

    setCharset(charset);
    r = new ArrayRecord(schema.getColumns().toArray(new Column[0]));
    nullBytes = nullTag.getBytes(defaultCharset);
}

From source file:com.strategicgains.docussandra.ParseUtils.java

/**
 * Converts a string to a date. Uses DateAdaptorJ, if that fails, falls back
 * to Natty.// w w  w.j a v a 2s.  c o  m
 *
 * @param in String to convert to a date.
 * @return A date based on the string.
 * @throws IndexParseFieldException If the field cannot be parsed as a date.
 */
public static Date parseStringAsDate(String in) throws IndexParseFieldException //TODO: come back to this and add more tests, i am not yet entirely happy with it
{
    DateAdapter adapter = new DateAdapter();
    try {
        return adapter.parse(in);
    } catch (ParseException e)//fall back to netty if that fails
    {
        Parser parser = new Parser(TimeZone.getTimeZone("GMT"));//assume all dates are GMT
        List<DateGroup> dg = parser.parse(in);
        if (dg.isEmpty()) {
            throw new IndexParseFieldException(in);
        }
        List<Date> dates = dg.get(0).getDates();
        if (dates.isEmpty()) {
            throw new IndexParseFieldException(in);
        }
        return dates.get(0);//dang; that actually works
    }
}

From source file:org.jsonschema2pojo.integration.CustomDateTimeFormatIT.java

/**
 * We are going to generate the same class twice:
 * Once with the configuration option formatDateTimes set to TRUE
 * Once with the configuration option formatDateTimes set to FALSE
 * /*  w  w  w.j a va2s  . c  o m*/
 * @throws ClassNotFoundException
 * @throws IOException
 */
@BeforeClass
public static void generateClasses() throws ClassNotFoundException, IOException {
    // The SimpleDateFormat instances created and configured here are based on the json schema defined in customDateTimeFormat.json
    dateTimeMilliSecFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    dateTimeMilliSecFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    dateTimeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    dateTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
    dateFormatter.setTimeZone(TimeZone.getTimeZone("PST"));

    Map<String, Object> configValues = new HashMap<String, Object>();

    // Generate class with config option formatDateTimes = TRUE
    configValues.put("formatDateTimes", Boolean.TRUE);
    classSchemaRule.generate("/schema/format/customDateTimeFormat.json", "com.example.config_true",
            configValues);

    // Generate class with config option formatDateTimes = FALSE
    configValues.put("formatDateTimes", Boolean.FALSE);
    classSchemaRule.generate("/schema/format/customDateTimeFormat.json", "com.example.config_false",
            configValues);

    ClassLoader loader = classSchemaRule.compile();

    // Class generated when formatDateTimes = TRUE in configuration
    classWhenConfigIsTrue = loader.loadClass("com.example.config_true.CustomDateTimeFormat");
    // Class generated when formatDateTimes = FALSE in configuration
    classWhenConfigIsFalse = loader.loadClass("com.example.config_false.CustomDateTimeFormat");
}

From source file:com.tango.logstash.flume.elasticsearch.sink.LogstashEventSerializerIndexRequestBuilderFactory.java

@Override
public void configure(Context context) {
    super.configure(context);

    // Ex: "yyyy-MM-dd"
    String indexFormatStr = context.getString(PARAM_INDEX_FORMAT);
    if (StringUtils.isNotBlank(indexFormatStr)) {
        indexFormater = FastDateFormat.getInstance(indexFormatStr, TimeZone.getTimeZone("Etc/UTC"));
    }//from   w w  w . j a v a2  s .co  m
}

From source file:GmtDate.java

/**
 *  Description of the Method//from  w ww  .  j  av  a 2  s . c  om
 *
 * @param  date  Description of the Parameter
 * @return       Description of the Return Value
 */
public final static String shortFormat(Date date) {
    shortFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    fullString = shortFormatter.format(date);
    return fullString.substring(0, 19);
    // makes new string
}

From source file:ca.uhn.hl7v2.model.primitive.CommonTSTest.java

@BeforeClass
public static void setUpBeforeClass() {
    tz = TimeZone.getDefault();//from   w  ww  .  j av a 2s.com
    TimeZone.setDefault(TimeZone.getTimeZone("Canada/Eastern"));
}

From source file:edu.jhu.pha.vospace.jobs.JobsProcessor.java

public JobsProcessor() {
    jobsPoolSize = conf.getInt("maxtransfers");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    initProtocolHandlers();
}