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.xerox.amazonws.ec2.UploadPolicy.java

public String getPolicyString() {
    StringBuilder json = new StringBuilder("{\n");
    json.append("\"expiration\": \"");
    final String DateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    SimpleDateFormat format = new SimpleDateFormat(DateFormat, Locale.US);
    format.setTimeZone(TimeZone.getTimeZone("GMT"));
    json.append(format.format(new Date(System.currentTimeMillis() + (minutesToExpiration * 60000L))));
    json.append("\",\n");
    json.append("\"conditions\": [\n");

    json.append("{\"acl\": \"");
    json.append(acl);//from   www  .j  a va2  s  .  c  om
    json.append("\"},\n");

    json.append("{\"bucket\": \"");
    json.append(bucket);
    json.append("\"},\n");

    json.append("[\"starts-with\", \"$key\", \"");
    json.append(prefix);
    json.append("\"],\n");

    json.append("]\n}");
    logger.debug("JSON policy string = " + json.toString());
    return new String(Base64.encodeBase64(json.toString().getBytes()));
}

From source file:org.devgateway.toolkit.web.spring.MvcConfig.java

@Bean
public Jackson2ObjectMapperBuilder objectMapperBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();

    SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    builder.serializationInclusion(Include.NON_EMPTY).dateFormat(dateFormatGmt);
    builder.serializerByType(GeoJsonPoint.class, new GeoJsonPointSerializer());
    builder.serializerByType(ObjectId.class, new ToStringSerializer());
    builder.defaultViewInclusion(true);/*  www . ja v a2 s  .  c  o  m*/

    return builder;
}

From source file:de.fhg.iais.commons.time.StopWatch.java

public String stopTimeFormat(String format, TimeZone zone) {
    if (format == null || format.equals("")) {
        format = "'P'DDD'DT'HH'H'mm'M'ss'S'";
    }/*from   w w w.  j  ava2  s.c o  m*/
    if (zone == null) {
        zone = TimeZone.getTimeZone("GMT0");
    }
    long end = stop();
    if (end < this.daysMilliseconds) {
        Date endDate = new Date(end);
        SimpleDateFormat formatter = new SimpleDateFormat("'000D:'HH'h:'mm'm:'ss's'");
        formatter.setTimeZone(zone);
        return formatter.format(endDate);
    } else {
        end -= this.daysMilliseconds;
        Date endDate = new Date(end);
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        formatter.setTimeZone(zone);
        return formatter.format(endDate);
    }
}

From source file:com.webpagebytes.cms.controllers.LanguagesController.java

private WPBProject getProject() throws WPBIOException {
    WPBProject project = adminStorage.get(WPBProject.PROJECT_KEY, WPBProject.class);
    if (null == project) {
        project = new WPBProject();
        project.setPrivkey("wbprojectid");
        project.setDefaultLanguage("en");
        project.setLastModified(Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime());
        project.setSupportedLanguages("en");
        project = adminStorage.addWithKey(project);
    }/* w w w . ja  va2  s.  co m*/
    return project;
}

From source file:Main.java

/**
 * Parse a date from ISO-8601 formatted string. It expects a format
 * yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]
 *
 * @param date ISO string to parse in the appropriate format.
 * @return the parsed date/*from   w w w.  jav a 2 s.c  o  m*/
 * @throws IllegalArgumentException if the date is not in the appropriate format
 */
public static Date parse(String date) {
    try {
        int offset = 0;

        // extract year
        int year = parseInt(date, offset, offset += 4);
        checkOffset(date, offset, '-');

        // extract month
        int month = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, '-');

        // extract day
        int day = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, 'T');

        // extract hours, minutes, seconds and milliseconds
        int hour = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, ':');

        int minutes = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, ':');

        int seconds = parseInt(date, offset += 1, offset += 2);
        // milliseconds can be optional in the format
        // always use 0 otherwise returned date will include millis of current time
        int milliseconds = 0;

        if (date.charAt(offset) == '.') {
            checkOffset(date, offset, '.');
            int digitCount = 1;
            while (offset + digitCount < date.length() && digitCount < 3
                    && date.charAt(offset + 1 + digitCount) != 'Z'
                    && date.charAt(offset + 1 + digitCount) != '+'
                    && date.charAt(offset + 1 + digitCount) != '-') {
                digitCount++;
            }
            String msString = date.substring(offset += 1, offset += digitCount);
            while (msString.length() < 3) {
                msString += '0';
            }
            milliseconds = parseInt(msString, 0, 3);
        }

        // extract timezone
        String timezoneId = null;
        while (offset < date.length()) {
            char timezoneIndicator = date.charAt(offset);
            if (timezoneIndicator == '+' || timezoneIndicator == '-') {
                timezoneId = GMT_ID + date.substring(offset);
                break;
            } else if (timezoneIndicator == 'Z') {
                timezoneId = GMT_ID;
                break;
            }
            offset++;
        }
        if (timezoneId == null) {
            throw new IndexOutOfBoundsException("Invalid time zone indicator ");
        }
        TimeZone timezone = TimeZone.getTimeZone(timezoneId);
        if (!timezone.getID().equals(timezoneId)) {
            throw new IndexOutOfBoundsException();
        }

        Calendar calendar = new GregorianCalendar(timezone);
        calendar.setLenient(false);
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minutes);
        calendar.set(Calendar.SECOND, seconds);
        calendar.set(Calendar.MILLISECOND, milliseconds);

        return calendar.getTime();
    } catch (IndexOutOfBoundsException | IllegalArgumentException e) {
        throw new IllegalArgumentException("Failed to parse date " + date, e);
    }
}

From source file:Main.java

private static int getDiffTimeZoneRawOffset(String srcZoneId, String toZoneId) {
    return TimeZone.getTimeZone(srcZoneId).getRawOffset() - TimeZone.getTimeZone(toZoneId).getRawOffset();
}

From source file:no.met.jtimeseries.marinogram.MarinogramPlot.java

public MarinogramPlot(int width, int height, String timezone, String language) {
    this(width, language);
    this.height = height;
    this.timezone = TimeZone.getTimeZone(timezone);
}

From source file:it.reply.orchestrator.resource.common.AbstractResource.java

private String convertDate(Date date) {
    TimeZone tz = TimeZone.getTimeZone("UTC");
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
    df.setTimeZone(tz);/*from   ww  w .  j ava2 s  .  co m*/
    return df.format(date);
}

From source file:at.alladin.rmbt.shared.Helperfunctions.java

public static Calendar getTimeWithTimeZone(final String timezoneId) {

    final TimeZone timeZone = TimeZone.getTimeZone(timezoneId);

    final Calendar timeWithZone = Calendar.getInstance(timeZone);

    return timeWithZone;
}

From source file:org.apache.unomi.persistence.spi.CustomObjectMapper.java

public CustomObjectMapper() {
    super();//  www .  ja va2  s.  c  o m
    super.registerModule(new JaxbAnnotationModule());
    configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    ISO8601DateFormat dateFormat = new ISO8601DateFormat();
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    setDateFormat(dateFormat);
    SimpleModule deserializerModule = new SimpleModule("PropertyTypedObjectDeserializerModule",
            new Version(1, 0, 0, null, "org.apache.unomi.rest", "deserializer"));

    PropertyTypedObjectDeserializer propertyTypedObjectDeserializer = new PropertyTypedObjectDeserializer();
    propertyTypedObjectDeserializer.registerMapping("type=.*Condition", Condition.class);
    deserializerModule.addDeserializer(Object.class, propertyTypedObjectDeserializer);

    ItemDeserializer itemDeserializer = new ItemDeserializer();
    deserializerModule.addDeserializer(Item.class, itemDeserializer);

    Map<String, Class<? extends Item>> classes = new HashMap<>();
    classes.put(Campaign.ITEM_TYPE, Campaign.class);
    classes.put(CampaignEvent.ITEM_TYPE, CampaignEvent.class);
    classes.put(Event.ITEM_TYPE, Event.class);
    classes.put(Goal.ITEM_TYPE, Goal.class);
    classes.put(Persona.ITEM_TYPE, Persona.class);
    classes.put(Rule.ITEM_TYPE, Rule.class);
    classes.put(Scoring.ITEM_TYPE, Scoring.class);
    classes.put(Segment.ITEM_TYPE, Segment.class);
    classes.put(Session.ITEM_TYPE, Session.class);
    classes.put(ConditionType.ITEM_TYPE, ConditionType.class);
    classes.put(ActionType.ITEM_TYPE, ActionType.class);
    for (Map.Entry<String, Class<? extends Item>> entry : classes.entrySet()) {
        propertyTypedObjectDeserializer.registerMapping("itemType=" + entry.getKey(), entry.getValue());
        itemDeserializer.registerMapping(entry.getKey(), entry.getValue());
    }
    propertyTypedObjectDeserializer.registerMapping("itemType=.*", CustomItem.class);

    super.registerModule(deserializerModule);
}