0

on one site which i want to grab, i have a format date and time like this:

<div id="date">11 october 2010 <span>|</span> 21:43</div>

at first i want to split the time and date in two variables, and after this push it to my table in my mysql.

as well as i need to change the format date in smth like this: 2013-05-10

now i have only this:

String date = (driver.findElement(By.id("date"))).getText();

how can i split and change format of this?

1
  • 1
    You want to change the format of the date? Commented Oct 11, 2013 at 16:56

1 Answer 1

2

I suppose the date string contains something like "11 october 2010 | 21:43". You can use SimpleDateFormat for this. In your case this should work:

SimpleDateFormat simpleDateFormatIn =
        new SimpleDateFormat("dd MMMM yyyy '|' HH:mm", Locale.ENGLISH);
SimpleDateFormat simpleDateFormatOut =
        new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);

String dateStr = (driver.findElement(By.id("date"))).getText();
Date date = simpleDateFormatIn.parse(dateStr);

System.out.println(simpleDateFormatOut.format(date));

A nice little blog about this can be found here:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.