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.xeiam.xchange.btce.service.marketdata.BTCETickerJSONTest.java

@Test
public void testUnmarshal() throws IOException {

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

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

    // Verify that the example data was unmarshalled correctly
    assertThat(BTCETicker.getTicker().getLast()).isEqualTo(new BigDecimal("13.07"));
    assertThat(BTCETicker.getTicker().getHigh()).isEqualTo(new BigDecimal("13.23"));
    assertThat(BTCETicker.getTicker().getLow()).isEqualTo(new BigDecimal("13"));
    assertThat(BTCETicker.getTicker().getVol()).isEqualTo(new BigDecimal("40418.44988"));

    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    f.setTimeZone(TimeZone.getTimeZone("UTC"));
    String dateString = f.format(DateUtils.fromMillisUtc(BTCETicker.getTicker().getServerTime() * 1000L));
    assertThat(dateString).isEqualTo("2012-12-22 19:12:09");
}

From source file:jp.classmethod.aws.brian.utils.BrianServerObjectMapperFactoryBean.java

@Override
protected ObjectMapper createInstance() {
    ObjectMapper mapper = new ObjectMapper();
    SimpleModule brianModule = new SimpleModule("brianServerModule", VERSION);
    brianModule.addSerializer(Trigger.class, new TriggerSerializer());
    mapper.registerModule(brianModule);//from  w  w w.java2  s  .  c  o m
    mapper.registerModule(new Jdk8Module());

    mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    df.setTimeZone(TimeZones.UNIVERSAL);
    mapper.setDateFormat(df);

    return mapper;
}

From source file:lucee.runtime.net.smtp.SMTPClient.java

public static String getNow(TimeZone tz) {
    tz = ThreadLocalPageContext.getTimeZone(tz);
    SimpleDateFormat df = formatters.get(tz);
    if (df == null) {
        df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z (z)", Locale.US);
        df.setTimeZone(tz);
        formatters.put(tz, df);// ww w .j  a  va 2 s  .  c  o m
    }
    return df.format(new Date());
}

From source file:guru.nidi.loader.url.SimpleUrlFetcher.java

private String httpDate(long date) {
    final SimpleDateFormat format = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.ENGLISH);
    format.setTimeZone(TimeZone.getTimeZone("GMT"));
    return format.format(date);
}

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);/*from   ww w .j a  va 2  s .  c  om*/

    return builder;
}

From source file:com.capgemini.parking.places.ParkingGroupFactory.java

private Long getTimeStampFrom(String timestamp) {
    Long time = 1L;//from  www  .ja  v a  2  s  .  c  o  m
    try {
        SimpleDateFormat date = new SimpleDateFormat(configuration.getDate());
        date.setTimeZone(TimeZone.getTimeZone(configuration.getTimezone()));
        return date.parse(timestamp).getTime();
    } catch (ParseException ex) {
        ex.printStackTrace();
    }
    return time;
}

From source file:nz.net.orcon.kanban.tools.MapJsonSerializer.java

@Override
public void serialize(Map<String, Object> fields, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    jgen.writeStartObject();// w  w  w  .  j av a  2s .  c  o m
    for (Entry<String, Object> entry : fields.entrySet()) {
        Object objectValue = entry.getValue();
        if (objectValue instanceof Date) {
            Date date = (Date) objectValue;
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland"));
            String formattedDate = simpleDateFormat.format(date);
            jgen.writeObjectField(entry.getKey().toString(), formattedDate);
        } else {
            jgen.writeObjectField(entry.getKey().toString(), objectValue);
        }
    }
    jgen.writeEndObject();
}

From source file:android.framework.org.apache.harmony.security_custom.asn1.ASN1UTCTime.java

@Override
public void setEncodingContent(BerOutputStream out) {
    SimpleDateFormat sdf = new SimpleDateFormat(UTC_PATTERN);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    out.content = sdf.format(out.content).getBytes(Charsets.UTF_8);
    out.length = ((byte[]) out.content).length;
}

From source file:info.archinnov.achilles.it.bugs.TestDSLUpdateWithTTLAndTimestamp.java

private Date buildDateKey() throws ParseException {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return dateFormat.parse("2015-10-01 00:00:00 GMT");
}

From source file:com.boozallen.cognition.ingest.storm.bolt.logging.LogRecordDateBolt.java

void logDate(LogRecord record) {
    Date date = record.getDate();
    if (date == null) {
        logger.error("Record date is null!");
    } else {//from  w ww .  ja va  2 s  .  c om
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        sdf.setTimeZone(TimeZone.getTimeZone(ZoneId.of("UTC")));
        super.log(logger, sdf.format(date));
    }
}