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:org.runnerup.export.EndomondoSynchronizer.java

private void parseFeed(FeedUpdater feedUpdater, JSONObject reply) throws JSONException {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss 'UTC'", Locale.getDefault());
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    JSONArray arr = reply.getJSONArray("data");
    for (int i = 0; i < arr.length(); i++) {
        JSONObject o = arr.getJSONObject(i);
        try {/*  w  w  w.  j  a  va  2s  .  c  o  m*/
            if ("workout".contentEquals(o.getString("type"))) {
                final ContentValues c = parseWorkout(df, o);
                feedUpdater.add(c);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.dasein.cloud.aws.AWSCloud.java

/**
 * Gets the epoch form of the text value of the provided node.
 *
 * @param node the node to extact the value from
 * @return the epoch time/*  w  w w. jav  a2 s  .co m*/
 * @throws CloudException
 */
public static long getTimestampValue(Node node) throws CloudException {
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
    String value = getTextValue(node);

    try {
        return fmt.parse(value).getTime();
    } catch (ParseException e) {
        logger.error(e);
        e.printStackTrace();
        throw new CloudException(e);
    }
}

From source file:org.ednovo.gooru.service.ResourceCassandraServiceImpl.java

public void saveResourceStatus(String url, Integer statusCode, String gooruOid, boolean resourceInsdexStatus) {

    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
    String indexing_done = "0";
    if (resourceInsdexStatus) {
        indexing_done = "1";
    }//from  ww w  .jav  a 2 s. com
    dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    Map<String, String> resourceStatus = new HashMap<String, String>();
    resourceStatus.put(URL, url);
    resourceStatus.put(LAST_UPDATED, dateFormatter.format(new Date()).toString());
    resourceStatus.put(URL_STATUS, statusCode.toString());
    resourceStatus.put(INDEXING_DONE, indexing_done);
    if (statusCode == 200 || statusCode == 302 || statusCode == 301) {
        resourceStatus.put(RESOURCE_STATUS, "1");
    } else {
        resourceStatus.put(RESOURCE_STATUS, "0");
    }
    this.save(gooruOid, resourceStatus, ColumnFamilyType.RESOURCE_STATUS);

}

From source file:eu.scape_project.tool.toolwrapper.toolwrapper_bash_generator.BashWrapperGenerator.java

/** Public empty constructor (setting all instance variables to null) */
public BashWrapperGenerator() {
    super();//ww w .  j  a  v a2s . c  om
    tool = null;
    components = null;
    component = null;
    operation = null;
    wrapperName = null;
    bashWrapperTemplate = null;
    SimpleDateFormat sdf = new SimpleDateFormat(Constants.FULL_DATE_WITH_TIMEZONE);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    generationDate = sdf.format(new Date());

    Options options = super.getOptions();
    Option opt = new Option("c", "components", true, "components spec file location");
    opt.setRequired(false);
    options.addOption(opt);
}

From source file:fi.kela.kanta.cda.Purkaja.java

/**
 * Apumetodi ajanpurkamiseen parsii annetun ajan jos aika ei ole null eik sisll muuta kuin numeroita olettaa ett
 * aika annetaan yyyyMMddHHmmss formaatissa Jos annettu aika pitempikuin 14 merkki, yli menev osa ptkistn pois
 * Jos formaatti pattern on pidempi kuin annettu aika, ptkistn siit ylimenev osa pois
 *
 * @param aika/*from w w  w . ja  v a  2s . co  m*/
 *            String purettava aika
 * @return Date tai null jos annettu null tai liian lyhyt tai ei numeroita sisltv merkkijono
 * @throws PurkuException
 */
protected Date puraAika(String aika) throws PurkuException {
    if (aika != null) {
        String lyhytAika;
        if (aika.length() > Purkaja.sdfKuvio.length()) {
            lyhytAika = aika.substring(0, Purkaja.sdfKuvio.length());
        } else {
            lyhytAika = aika;
        }
        // 0000-99999999999999
        if (lyhytAika.matches("[0-9]{4,14}")) {
            SimpleDateFormat sdf = new SimpleDateFormat(Purkaja.sdfKuvio.substring(0, lyhytAika.length()));
            sdf.setTimeZone(TimeZone.getTimeZone(ReseptiKasaaja.TIME_ZONE));
            try {
                return sdf.parse(lyhytAika);
            } catch (ParseException e) {
                throw new PurkuException(aika);
            }
        }
    }
    return null;
}

From source file:org.adempiere.webui.dashboard.CalendarWindow.java

public void onEvent(Event e) throws Exception {
    String type = e.getName();//  w  ww .j  ava  2 s.c o m

    if (type.equals(Events.ON_CLICK)) {
        if (e.getTarget() == btnRefresh)
            btnRefreshClicked();
        else if (e.getTarget() == btnCurrentDate)
            btnCurrentDateClicked();
        else if (e.getTarget() == btnSwitchTimeZone)
            btnSwitchTimeZoneClicked();
    } else if (type.equals(Events.ON_CREATE)) {
        if (e.getTarget() == lblDate)
            updateDateLabel();
        else if (e.getTarget() == FDOW)
            FDOW.setVisible("month".equals(calendars.getMold()) || calendars.getDays() == 7);
        else if (e.getTarget() == myChart)
            syncModel();
        else if (e.getTarget() == lbxFDOW)
            lbxFDOW.setSelectedIndex(0);
    } else if (type.equals("onMoveDate")) {
        if (e.getTarget() == divArrowLeft)
            divArrowClicked(false);
        else if (e.getTarget() == divArrowRight)
            divArrowClicked(true);
    } else if (type.equals("onUpdateView")) {
        String text = String.valueOf(e.getData());
        int days = Msg.getMsg(Env.getCtx(), "Day").equals(text) ? 1
                : Msg.getMsg(Env.getCtx(), "5Days").equals(text) ? 5
                        : Msg.getMsg(Env.getCtx(), "Week").equals(text) ? 7 : 0;
        divTabClicked(days);
    } else if (type.equals(Events.ON_SELECT)) {
        if (e.getTarget() == lbxRequestTypes) {
            Listitem li = lbxRequestTypes.getSelectedItem();
            if (li == null)
                return;

            if (li.getValue() == null)
                return;
            int R_RequestType_ID = Integer.parseInt(li.getValue().toString());

            scm.clear();
            ArrayList<ADCalendarEvent> events = DPCalendar.getEvents(R_RequestType_ID, Env.getCtx());
            for (ADCalendarEvent event : events)
                scm.add(event);

            calendars.invalidate();
            syncModel();
        } else if (e.getTarget() == lbxFDOW) {
            calendars.setFirstDayOfWeek(lbxFDOW.getSelectedItem().getValue().toString());
            syncModel();
        }
    } else if (type.equals("onEventCreate")) {
        if (e instanceof CalendarsEvent) {
            CalendarsEvent calendarsEvent = (CalendarsEvent) e;
            RequestWindow requestWin = new RequestWindow(calendarsEvent, this);
            SessionManager.getAppDesktop().showWindow(requestWin);
        }
    } else if (type.equals("onEventEdit")) {
        if (e instanceof CalendarsEvent) {
            CalendarsEvent calendarsEvent = (CalendarsEvent) e;
            CalendarEvent calendarEvent = calendarsEvent.getCalendarEvent();

            if (calendarEvent instanceof ADCalendarEvent) {
                ADCalendarEvent ce = (ADCalendarEvent) calendarEvent;

                if (eventWin == null)
                    eventWin = new EventWindow();
                eventWin.setData(ce);
                SessionManager.getAppDesktop().showWindow(eventWin);
            }
        }
    } else if (type.equals("onEventUpdate")) {
        if (e instanceof CalendarsEvent) {
            CalendarsEvent evt = (CalendarsEvent) e;
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/d");
            sdf1.setTimeZone(calendars.getDefaultTimeZone());
            StringBuilder sb = new StringBuilder("Update... from ");
            sb.append(sdf1.format(evt.getCalendarEvent().getBeginDate()));
            sb.append(" to ");
            sb.append(sdf1.format(evt.getBeginDate()));
            popupLabel.setValue(sb.toString());
            int left = evt.getX();
            int top = evt.getY();
            if (top + 100 > evt.getDesktopHeight())
                top = evt.getDesktopHeight() - 100;
            if (left + 330 > evt.getDesktopWidth())
                left = evt.getDesktopWidth() - 330;
            updateMsg.open(left, top);
            timer.start();
            org.zkoss.calendar.Calendars cal = (org.zkoss.calendar.Calendars) evt.getTarget();
            SimpleCalendarModel m = (SimpleCalendarModel) cal.getModel();
            SimpleCalendarEvent sce = (SimpleCalendarEvent) evt.getCalendarEvent();
            sce.setBeginDate(evt.getBeginDate());
            sce.setEndDate(evt.getEndDate());
            m.update(sce);
        }
    }
}

From source file:com.vkassin.mtrade.Common.java

public static String sign(String login, String passwd) {
    String msgKey = "aW3f!@Jm<h&*9>?g";
    SimpleDateFormat sdf = new SimpleDateFormat("|yyyy|(MM)[dd*HH]");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    Calendar currentTime = Calendar.getInstance();
    String currDateTime = sdf.format(currentTime.getTime());
    return getMd5(login + "-" + passwd + "-" + currDateTime + "-" + msgKey);
}

From source file:jp.co.opentone.bsol.linkbinder.view.logo.ProjectLogoManagerTest.java

/**
 * projectId:??ifModifiedSince:??/*from   w ww . ja  v  a2s .  co m*/
 */
@Test
public void testIsModified15() {
    String projectId = "test-project";

    String testFile = MockSystemConfig.CONFIG_PROJECT_LOGO_DIR + "/" + projectId + ".png";
    File f = new File(testFile);
    if (!f.exists()) {
        fail("?[" + testFile + "] ????????");
        return;
    }

    MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT = "test-default.png";
    String testFile2 = MockSystemConfig.CONFIG_PROJECT_LOGO_DIR + "/"
            + MockSystemConfig.CONFIG_PROJECT_LOGO_DEFAULT;
    File f2 = new File(testFile2);
    if (!f2.exists()) {
        fail("?[" + testFile2 + "] ????????");
        return;
    }

    SimpleDateFormat rfc1123DateFormat = new SimpleDateFormat("E, dd MMM yyyy hh:mm:ss.000 zzz");
    rfc1123DateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    String ifModifiedSince = rfc1123DateFormat.format(new Date(f.lastModified()));

    assertTrue(projectLogoManager.isModified(projectId, ifModifiedSince));
}

From source file:net.kourlas.voipms_sms.model.Message.java

/**
 * Initializes a new instance of the Message class. This constructor is intended for use when creating a Message
 * object using information from the VoIP.ms API.
 *
 * @param voipId  The ID assigned to the message by VoIP.ms.
 * @param date    The UNIX timestamp of the message.
 * @param type    The type of the message (1 for incoming, 0 for outgoing).
 * @param did     The DID associated with the message.
 * @param contact The contact associated with the message.
 * @param text    The text of the message.
 *///from   w w w .ja v  a2  s. c om
public Message(String voipId, String date, String type, String did, String contact, String text)
        throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    sdf.setTimeZone(TimeZone.getTimeZone("America/New_York"));

    this.databaseId = null;

    this.voipId = Long.parseLong(voipId);

    this.date = sdf.parse(date);

    if (!type.equals("0") && !type.equals("1")) {
        throw new IllegalArgumentException("type must be 0 or 1.");
    }
    this.type = type.equals("1") ? Type.INCOMING : Type.OUTGOING;

    if (!did.replaceAll("[^0-9]", "").equals(did)) {
        throw new IllegalArgumentException("did must consist only of numbers.");
    }
    this.did = did;

    if (!contact.replaceAll("[^0-9]", "").equals(contact)) {
        throw new IllegalArgumentException("contact must consist only of numbers.");
    }
    this.contact = contact;

    this.text = text;

    this.isUnread = type.equals("1");

    this.isDeleted = false;

    this.isDelivered = true;

    this.isDeliveryInProgress = false;

    this.uniqueObjectIdentifier = uniqueObjectIdentifierCount++;
}

From source file:de.phillme.PhotoSorter.java

private PhotoEvent handleEvent() {
    SimpleDateFormat sdfEurope = new SimpleDateFormat(this.dateFormatFolders);
    sdfEurope.setTimeZone(this.timeZone);
    String sDateinEurope = sdfEurope.format(this.eventStartDate) + this.eventFileSuffix;
    LOGGER.finest(sDateinEurope + " would be created as an event folder.\n");
    //File eventFile = new File(this.photosPath + File.separator + sDateinEurope);

    //eventFile.createNewFile();

    return new PhotoEvent(this.eventStartDate, this.eventEndDate);
}