Answer the question
In order to leave comments, you need to log in
C# How to change date format in text string?
Hello! Running some tests on my site using Selenium + C# . I came across this unpleasant story:
The site has a block in which 3-5 lines of text in this format:
Hard disk usage periods:
from 11/01/2011 to 02/21/2012: Datacenter1
from 03/28/2012 to 08/12/2017: Datacenter2
from 08/12/2017 .2017 and at the moment: Datacenter3
I get these lines in the collection in this way:
IList<IWebElement> Collection = Driver.FindElements(By.CssSelector("#checkHardDrive > div > ul.Periods li"));
foreach (IWebElement element in Collection )
{
this.period.BeginInvoke(updateTextPeriod, element.Text);
Thread.Sleep(100);
}
Answer the question
In order to leave comments, you need to log in
1 - if the date is displayed in your browser as you need * - look for another way to get the data
2 - if this is not possible, you will have to parse each line yourself, select the dates, convert them, and only then display them. such is the programmer's
life
after that, glue everything back into one lineit's not necessary, it's enough to replace the date in the "bad format" with the "good" one
in the browser the date is displayed as you need- 99% that there is a way to get the string you need right away. if not, in general, such a task is not very difficult, and quite useful for developing skills
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question