Example usage for java.text DateFormat parse

List of usage examples for java.text DateFormat parse

Introduction

In this page you can find the example usage for java.text DateFormat parse.

Prototype

public Date parse(String source) throws ParseException 

Source Link

Document

Parses text from the beginning of the given string to produce a date.

Usage

From source file:com.balch.mocktrade.finance.QuoteYahooFinance.java

@Override
public Date getLastTradeTime() {
    DateFormat df = new SimpleDateFormat("M/d/yy h:mma", Locale.US);
    df.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    String dateStr = this.data.get(LastTradeDate) + " " + this.data.get(LastTradeTime).toUpperCase();
    try {/*from w  w w  .j  a  v a2  s  . c  o m*/
        return df.parse(dateStr);
    } catch (ParseException e) {
        Log.e(TAG, "Error parsing date:" + dateStr, e);
        throw new RuntimeException(e);
    }
}

From source file:com.telefonica.euro_iaas.paasmanager.rest.auth.OpenStackAuthenticationTokenTest.java

@Test
public void shouldExtractAndValidateData() throws ParseException {
    // given/*from  w  w w .  ja va  2s .  c  o  m*/
    String keystoneURL = "http://localhost:4731/v2.0/";
    String adminUser = "admin";
    String adminPass = "aaaaaaaa";
    String adminTenant = "00000000000000000000000000001";
    Long threshold = 84000000L;

    ArrayList<Object> params = new ArrayList();
    params.add(keystoneURL);
    params.add(adminTenant);
    params.add(adminUser);
    params.add(adminPass);
    HttpClient httpClient = mock(HttpClient.class);
    params.add(httpClient);
    params.add(threshold);

    OpenStackAuthenticationToken openStackAuthenticationToken = new OpenStackAuthenticationToken(params);
    String response1 = "<access xmlns=\"http://docs.openstack.org/identity/api/v2.0\">\n"
            + "  <token expires=\"2015-07-09T15:16:07Z\" id=\"252f966e16b2514aa521fa885f0f4d03\">\n"
            + "    <tenant enabled=\"true\" id=\"00000000000000000000000000000001\" name=\"tenantname\" />\n"
            + "  </token>\n" + "  <user username=\"admin\" id=\"admin\" name=\"admin\">\n"
            + "    <roles_links/>\n"
            + "    <roles name=\"Member\" id=\"8db87ccbca3b4d1ba4814c3bb0d63aaf\"></roles>\n"
            + "    <roles name=\"admin\" id=\"09e95db0ea3f4495a64e95bfc64b0c56\"></roles>\n" + "  </user>\n"
            + "</access>";
    String response2 = "Tue Dec 10 12:46:50 CET 2014";

    String dateString = "Tue Dec 10 12:45:50 CET 2014";
    DateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss z YYYY", Locale.ENGLISH);
    Date response3 = format.parse(dateString);

    ArrayList<Object> response = new ArrayList<>();
    response.add(response1);
    response.add(response2);
    response.add(response3);

    // when
    openStackAuthenticationToken.extractData(response);

    // then
}

From source file:markson.visuals.sitapp.eventActivity.java

public void addtocal() throws ParseException {
    String location = null;/*from   w  w  w  . ja v a2  s .  co  m*/

    DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US);
    formatter.setTimeZone(TimeZone.getTimeZone("America/New_York"));
    Date StartTime = formatter.parse(date);
    Log.e("n", String.valueOf(StartTime.getTime()));

    Intent calint = new Intent(Intent.ACTION_INSERT);
    calint.setType("vnd.android.cursor.item/event");
    calint.putExtra("title", name);
    calint.putExtra("description", description);
    calint.putExtra("beginTime", StartTime.getTime());
    //calint.putExtra(Events.EVENT_TIMEZONE, "America/New_York");

    if (description.contains("at")) {

        location = description.substring(description.lastIndexOf("at") + 3, description.length());
        calint.putExtra("eventLocation", location);
    }

    startActivity(calint);

}

From source file:com.luna.common.repository.search.SearchUserRepositoryIT.java

@Test
public void testEqForDate() throws ParseException {
    int count = 15;
    String dateStr = "2012-01-15 16:59:00";
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (int i = 0; i < count; i++) {
        User user = createUser();/* w  w  w .  j  a v  a 2s.c om*/
        user.setRegisterDate(df.parse(dateStr));
        userRepository.save(user);
    }
    Map<String, Object> searchParams = new HashMap<String, Object>();
    searchParams.put("registerDate_eq", dateStr);
    SearchRequest search = new SearchRequest(searchParams);
    assertEquals(count, userRepository.count(search));
}

From source file:be.fedict.eidviewer.lib.file.Version4XMLFileIdentity.java

public void toIdentity(Identity eidIdentity) throws ParseException {
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    eidIdentity.nationalNumber = getNationalNumber();

    GregorianCalendar birthDateCalendar = new GregorianCalendar();
    birthDateCalendar.setTime(dateFormat.parse(getDateOfBirth()));
    eidIdentity.dateOfBirth = birthDateCalendar;
    eidIdentity.gender = getGender().equals("male") ? Gender.MALE : Gender.FEMALE;

    if (getNobleCondition() != null)
        eidIdentity.nobleCondition = getNobleCondition();

    if (getSpecialStatus() != null)
        eidIdentity.specialStatus = SpecialStatus.valueOf(getSpecialStatus());
    else/*  w w  w  .j  a v  a2 s.  c  o m*/
        eidIdentity.specialStatus = SpecialStatus.NO_STATUS;

    if (getDuplicate() != null)
        eidIdentity.duplicate = getDuplicate();

    eidIdentity.name = getName();
    eidIdentity.firstName = getFirstName();
    eidIdentity.middleName = getMiddleNames();
    eidIdentity.nationality = getNationality();
    eidIdentity.placeOfBirth = getPlaceOfBirth();
}

From source file:com.carvoyant.modularinput.Program.java

@Override
public void streamEvents(InputDefinition inputs, EventWriter ew)
        throws MalformedDataException, XMLStreamException, IOException {

    Service splunkSvc = getService(inputs.getServerUri(), inputs.getSessionKey());

    for (String inputName : inputs.getInputs().keySet()) {
        String clientId = ((SingleValueParameter) inputs.getInputs().get(inputName).get("clientId")).getValue();
        String clientSecret = ((SingleValueParameter) inputs.getInputs().get(inputName).get("clientSecret"))
                .getValue();//from  w  w w  .  j  a v  a2s  .  c o  m
        String token = ((SingleValueParameter) inputs.getInputs().get(inputName).get("token")).getValue();
        String refreshToken = ((SingleValueParameter) inputs.getInputs().get(inputName).get("refreshToken"))
                .getValue();

        SingleValueParameter expDate = (SingleValueParameter) inputs.getInputs().get(inputName)
                .get("expirationDate");
        long expirationDate = expDate.getLong();
        long expirationWindow = TimeUnit.DAYS.toMillis(1);
        long currentTime = System.currentTimeMillis();

        // If the access token is going to expire, then refresh it
        if ((expirationDate - currentTime) < expirationWindow) {
            JSONObject tokenJson = getRefreshToken(ew, clientId, clientSecret, refreshToken);

            if (tokenJson != null) {
                token = tokenJson.getString("access_token");
                refreshToken = tokenJson.getString("refresh_token");
                int ttl = tokenJson.getInt("expires_in");
                expirationDate = System.currentTimeMillis() + (long) ttl * 1000;

                // Update this configuration with the new settings
                String[] splunkApiInputName = inputName.split("://");
                updateInput(ew, splunkSvc, splunkApiInputName[1], clientId, clientSecret, token, refreshToken,
                        expirationDate);
            } else {
                throw new XMLStreamException("Cannot not refresh the token for " + inputName);
            }
        }

        // Get Carvoyant Data
        try {
            URL url = new URL("https://api.carvoyant.com/v1/api/account/data/?sinceLastCall=true");
            //            URL url = new URL("https://sandbox-api.carvoyant.com/sandbox/api/account/data/?sinceLastCall=true");
            URLConnection urlConnection = url.openConnection();

            String basicAuth = "Bearer " + token;
            urlConnection.setRequestProperty("Authorization", basicAuth);

            BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {

                JSONObject obj = new JSONObject(inputLine);
                JSONArray arr = obj.getJSONArray("data");

                for (int i = 0; i < arr.length(); i++) {
                    String timeString = arr.getJSONObject(i).getString("timestamp");
                    DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmssZ");
                    Date date = format.parse(timeString);

                    Event event = new Event();
                    event.setStanza(inputName);
                    event.setTime(date);
                    event.setData(arr.getJSONObject(i).toString());
                    ew.writeEvent(event);
                }
            }

            in.close();
        } catch (IOException ioe) {
            throw new XMLStreamException("Could not retrieve Carvoyant Data", ioe);
        } catch (ParseException pe) {
            throw new XMLStreamException("Could not parse Carvoyant Data", pe);
        }
    }
}

From source file:at.create.android.ffc.domain.Contact.java

/**
 * @param bornOn/*from  w  ww . j  a v  a  2s .  c  o m*/
 */
public void setBornOn(String bornOn) {
    if (!TextUtils.isEmpty(bornOn)) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            this.bornOn = new Date(dateFormat.parse(bornOn).getTime());
        } catch (ParseException e) {
            Log.e(TAG, "Can not parse born on date: \"" + bornOn + "\"", e);
        }
    }
}

From source file:com.luna.common.repository.search.SearchUserRepository2WithRepository2ImpIT.java

@Test
public void testLtAndGtForDate() throws ParseException {
    int count = 15;
    String dateStr = "2012-01-15 16:59:00";
    String dateStrFrom = "2012-01-15 16:58:00";
    String dateStrEnd = "2012-01-15 16:59:01";
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (int i = 0; i < count; i++) {
        User user = createUser();// w w  w  .j  av  a 2  s  . c  o  m
        user.getBaseInfo().setBirthday(new Timestamp(df.parse(dateStr).getTime()));
        userRepository2.save(user);
    }
    Map<String, Object> searchParams = new HashMap<String, Object>();
    searchParams.put("baseInfo.birthday_gt", dateStrFrom);
    searchParams.put("baseInfo.birthday_lt", dateStrEnd);
    Searchable search = Searchable.newSearchable(searchParams);
    assertEquals(count, userRepository2.count(search));
}

From source file:com.luna.common.repository.search.SearchUserRepository2WithRepository2ImpIT.java

@Test
public void testLteAndGteForDate() throws ParseException {
    int count = 15;
    String dateStr = "2012-01-15 16:59:00";
    String dateStrFrom = "2012-01-15 16:59:00";
    String dateStrEnd = "2012-01-15 16:59:00";
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (int i = 0; i < count; i++) {
        User user = createUser();/*from w w  w  .  jav a2  s  .c  om*/
        user.getBaseInfo().setBirthday(new Timestamp(df.parse(dateStr).getTime()));
        userRepository2.save(user);
    }
    Map<String, Object> searchParams = new HashMap<String, Object>();
    searchParams.put("baseInfo.birthday_gte", dateStrFrom);
    searchParams.put("baseInfo.birthday_lte", dateStrEnd);
    Searchable search = Searchable.newSearchable(searchParams);
    assertEquals(count, userRepository2.count(search));
}

From source file:annis.libgui.AnnisBaseUI.java

public Date getBuildDate() {
    Date result = null;/*from  w  w  w.  ja va  2s. c om*/
    try {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
        result = format.parse(versionProperties.getProperty("build_date"));
    } catch (Exception ex) {
        log.debug(null, ex);
    }
    return result;
}