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.chart.Utility.java

public static int getHourOfDayUTC(Date time) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.setTime(time);//from   ww  w. j ava  2  s  .co m
    return calendar.get(Calendar.HOUR_OF_DAY);
}

From source file:com.scraper.SignedRequestsHelper.java

private String timestamp() {
    String timestamp = null;//from   w w w.ja  v a  2s .c om
    Calendar cal = Calendar.getInstance();
    DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dfm.setTimeZone(TimeZone.getTimeZone("GMT"));
    timestamp = dfm.format(cal.getTime());
    return timestamp;
}

From source file:com.blackducksoftware.integration.hub.rest.RestConnection.java

public static Date parseDateString(final String dateString) throws ParseException {
    final SimpleDateFormat sdf = new SimpleDateFormat(JSON_DATE_FORMAT);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    return sdf.parse(dateString);
}

From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java

@Override
protected void setUp() {
    super.setUp();
    this.oldTimeZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
    Locale.setDefault(Locale.US);
    gson = new Gson();
}

From source file:org.sbq.batch.mains.SchedulerRunner.java

private void scheduleCalculateOnlineMetrics() throws SchedulerException {
    JobDetail job = newJob(CalculateOnlineMetricsScheduledJob.class)
            .withIdentity("calculateOnlineMetricsScheduledJob", "MetricsCollectors").requestRecovery(false)
            .build();/*from  w w w  .  ja  v a  2 s .c om*/
    CronTrigger trigger = newTrigger()
            .withIdentity("triggerFor_calculateOnlineMetricsScheduledJob", "MetricsCollectors")
            .withSchedule(cronSchedule("0/15 * * * * ?").inTimeZone(TimeZone.getTimeZone("UTC"))
                    .withMisfireHandlingInstructionIgnoreMisfires())
            .forJob(job.getKey()).build();
    scheduleJobWithTriggerIfNotPresent(job, trigger);
}

From source file:DateParser.java

/**
 * Parses the date value using the given date formats.
 * /*from   ww  w .  j a  v  a 2 s  . com*/
 * @param dateValue the date value to parse
 * @param dateFormats the date formats to use
 * 
 * @return the parsed date
 * 
 * @throws DateParseException if none of the dataFormats could parse the dateValue
 */
public static Date parseDate(String dateValue, Collection dateFormats) {

    if (dateValue == null) {
        throw new IllegalArgumentException("dateValue is null");
    }
    if (dateFormats == null) {
        dateFormats = DEFAULT_PATTERNS;
    }
    // trim single quotes around date if present
    // see issue #5279
    if (dateValue.length() > 1 && dateValue.startsWith("'") && dateValue.endsWith("'")) {
        dateValue = dateValue.substring(1, dateValue.length() - 1);
    }

    SimpleDateFormat dateParser = null;
    Iterator formatIter = dateFormats.iterator();

    while (formatIter.hasNext()) {
        String format = (String) formatIter.next();
        if (dateParser == null) {
            dateParser = new SimpleDateFormat(format, Locale.US);
            dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
        } else {
            dateParser.applyPattern(format);
        }
        try {
            return dateParser.parse(dateValue);
        } catch (ParseException pe) {
            // ignore this exception, we will try the next format
        }
    }

    // we were unable to parse the date
    throw new RuntimeException("Unable to parse the date " + dateValue);
}

From source file:com.kku.apps.pricesearch.util.SignedHelper.java

private static String timestamp() {
    String timestamp = null;//from   ww  w.  j  a  va  2 s  . com
    Calendar cal = Calendar.getInstance();
    DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dfm.setTimeZone(TimeZone.getTimeZone("GMT"));
    timestamp = dfm.format(cal.getTime());
    return timestamp;
}

From source file:com.intuit.wasabi.repository.cassandra.impl.ExperimentRuleCacheUpdateEnvelope.java

protected String getUTCTime() {
    Date currentTime = new Date();
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    return sdf.format(currentTime);
}

From source file:ly.stealth.xmlavro.ConverterTest.java

@Test
public void rootDateTimePrimitive() {
    rootPrimitiveWithType("xs:dateTime", "2014-10-30T14:58:33", Schema.Type.LONG, 1414681113000L);
    rootPrimitiveWithType("xs:dateTime", "2014-09-10T12:58:33", Schema.Type.LONG, 1410353913000L);

    DatumBuilder.setDefaultTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
    rootPrimitiveWithType("xs:dateTime", "2014-10-30T07:58:33", Schema.Type.LONG, 1414681113000L);
    rootPrimitiveWithType("xs:dateTime", "2014-09-10T05:58:33", Schema.Type.LONG, 1410353913000L);
}