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:jp.classmethod.aws.brian.utils.GsonFactoryBean.java

@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
    sdf.setTimeZone(TimeZone.getTimeZone("Universal"));
    return new JsonPrimitive(sdf.format(src));
}

From source file:ch.zhaw.icclab.tnova.expressionsolver.KPI.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*  ww w.j a  v  a2s  . co  m*/
public String showKPI() {
    KPI.api_calls += 1; //tracking the current call
    JSONObject obj = new JSONObject();
    obj.put("src", "t-nova expression evaluation service");
    obj.put("msg", "kpi parameters data");

    obj.put("api-calls-total", api_calls);
    obj.put("api-calls-failed", api_calls_failed);
    obj.put("expressions-evaluated", expressions_evaluated);
    obj.put("expressions-under-evaluation", expressions_under_evaluation);
    Date date = new Date(lastknownunixtime);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+1"));
    String formattedDate = sdf.format(date);
    obj.put("data-since", formattedDate);

    KPI.api_calls_success += 1;
    obj.put("api-calls-success", api_calls_success);
    //lastknownunixtime = System.currentTimeMillis();
    initialize();
    logger.info("URI:/kpi Method:GET Request procesed. The KPI parameters have been reset.");
    return obj.toJSONString();
}

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'";
    }/*  w  ww. j  ava  2  s .  c om*/
    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:android.framework.org.apache.harmony.security_custom.asn1.ASN1GeneralizedTime.java

public void setEncodingContent(BerOutputStream out) {
    SimpleDateFormat sdf = new SimpleDateFormat(GEN_PATTERN);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String temp = sdf.format(out.content);
    // cut off trailing 0s
    int nullId;//from   w  ww  .j av a2 s .c o  m
    int currLength;
    while (((nullId = temp.lastIndexOf('0', currLength = temp.length() - 1)) != -1) & (nullId == currLength)) {
        temp = temp.substring(0, nullId);
    }
    // deal with point (cut off if it is last char)
    if (temp.charAt(currLength) == '.') {
        temp = temp.substring(0, currLength);
    }

    out.content = (temp + "Z").getBytes(Charsets.UTF_8);
    out.length = ((byte[]) out.content).length;
}

From source file:com.persistent.cloudninja.scheduler.TenantDBBandwidthGenerator.java

@Override
public boolean execute() {
    StopWatch watch = new StopWatch();
    boolean retVal = true;
    try {/*from   w  w  w  .  j  av  a  2  s  .  c o m*/
        watch.start();
        LOGGER.debug("In generator");
        TenantDBBandwidthQueue queue = (TenantDBBandwidthQueue) getWorkQueue();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        String currentTime = dateFormat.format(calendar.getTime());
        queue.enqueue(currentTime);
        LOGGER.info("Generator : msg added is " + currentTime);
        watch.stop();
        taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                "GenerateMeterTenantDBBandwidthWork", "");
    } catch (StorageException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:net.servicefixture.converter.XMLGregorianCalendarConverter.java

public String toString(Object source) {
    XMLGregorianCalendar src = (XMLGregorianCalendar) source;
    SimpleDateFormat formatter = new SimpleDateFormat(DateConverter.DATE_FORMAT);
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, src.getYear());
    cal.set(Calendar.MONTH, src.getMonth() - 1);
    cal.set(Calendar.DAY_OF_MONTH, src.getDay());
    cal.set(Calendar.HOUR, src.getHour());
    cal.set(Calendar.MINUTE, src.getMinute());
    cal.set(Calendar.SECOND, src.getSecond());
    cal.set(Calendar.MILLISECOND, src.getMillisecond());
    return formatter.format(cal.getTime());
}

From source file:com.alliander.osgp.webdevicesimulator.service.OslpChannelHandler.java

private static Message createGetActualPowerUsageResponse() {
    // yyyyMMddhhmmss z
    final SimpleDateFormat utcTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    utcTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    final Date currentDateTime = new Date();
    final String utcTimestamp = utcTimeFormat.format(currentDateTime);

    @SuppressWarnings("deprecation")
    final int actualConsumedPower = currentDateTime.getMinutes();

    return Oslp.Message.newBuilder()
            .setGetActualPowerUsageResponse(GetActualPowerUsageResponse.newBuilder()
                    .setPowerUsageData(PowerUsageData.newBuilder().setRecordTime(utcTimestamp)
                            .setMeterType(MeterType.P1).setTotalConsumedEnergy(actualConsumedPower * 2L)
                            .setActualConsumedPower(actualConsumedPower)
                            .setPsldData(PsldData.newBuilder().setTotalLightingHours(actualConsumedPower * 3))
                            .setSsldData(SsldData.newBuilder().setActualCurrent1(1).setActualCurrent2(2)
                                    .setActualCurrent3(3).setActualPower1(1).setActualPower2(2)
                                    .setActualPower3(3).setAveragePowerFactor1(1).setAveragePowerFactor2(2)
                                    .setAveragePowerFactor3(3)
                                    .addRelayData(Oslp.RelayData.newBuilder()
                                            .setIndex(ByteString.copyFrom(new byte[] { 1 }))
                                            .setTotalLightingMinutes(480))
                                    .addRelayData(Oslp.RelayData
                                            .newBuilder().setIndex(ByteString.copyFrom(new byte[] { 2 }))
                                            .setTotalLightingMinutes(480))
                                    .addRelayData(Oslp.RelayData.newBuilder()
                                            .setIndex(ByteString.copyFrom(new byte[] { 3 }))
                                            .setTotalLightingMinutes(480))
                                    .addRelayData(Oslp.RelayData.newBuilder()
                                            .setIndex(ByteString.copyFrom(new byte[] { 4 }))
                                            .setTotalLightingMinutes(480))))
                    .setStatus(Oslp.Status.OK))
            .build();//from   ww w .j ava 2 s  .co  m
}

From source file:com.sugaronrest.restapicalls.responses.BaseResponse.java

/**
 * Initializes a new instance of the BaseResponse class
 *//*from   www.jav  a 2s  .c  o m*/
public BaseResponse() {

    final SimpleDateFormat format = new SimpleDateFormat(DATEFORMAT);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date currenTime = Calendar.getInstance().getTime();
    time = format.format(currenTime) + " UTC";
    this.setError(new ErrorResponse());
    this.statusCode = HttpStatus.SC_OK;
}

From source file:com.adobe.acs.commons.http.headers.impl.AbstractExpiresHeaderFilter.java

@Override
protected String getHeaderValue() {
    Calendar next = Calendar.getInstance();
    next.set(Calendar.HOUR_OF_DAY, expiresTime.get(Calendar.HOUR_OF_DAY));
    next.set(Calendar.MINUTE, expiresTime.get(Calendar.MINUTE));
    next.set(Calendar.SECOND, 0);

    adjustExpires(next);/* w  w w . ja v a2s.c o  m*/

    SimpleDateFormat dateFormat = new SimpleDateFormat(EXPIRES_FORMAT);
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return dateFormat.format(next.getTime());
}

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

public void testConvertDateAndTime() throws ParseException {
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    net.fortuna.ical4j.model.TimeZone tz = registry.getTimeZone("GMT");
    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());
}