我想在 YYYY-MM-DD 中获取日期后在 MM/DD/YYY 中添加日期
I want to add the date in MM/DD/YYY after getting the date in YYY-MM-DD
以下是我完成的步骤:
我已阅读 table 并在最后一行取了日期 - 日期为 YYY-MM-DD
日期增加 10,并以 YYY-MM-DD 格式显示结果。
但我的问题是我需要以 MM/DD/YYYY 格式输入日期,但我不确定该怎么做
下面是我的代码:
列出最后日期 = driver.findElements(By.xpath("(//table[包含(@class,'mat-table')]//tr/td[5] )[最后的()]”));
int rowcount = lastdate.size();
System.out.println("获取行数:"+rowcount);
for(int i=0;i<rowcount;i++)
{
String datetext = lastdate.get(i).getText();
//Specifying date format that matches the given date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
try{
//Setting the date to the given date
c.setTime(sdf.parse(datetext));- datetext - will take the date from the last row of the table which is 2000-04-15.
}catch(ParseException e){
e.printStackTrace();
}
//Number of Days to add
int daysToIncrement = 10;
c.add(Calendar.DATE, daysToIncrement);
//Date after adding the days to the given date
String newDate = sdf.format(c.getTime());
System.out.println("Get the New Date:"+newDate);
}
当我打印结果时 - 它显示日期为 2000-04-25
但我需要在 MM/DD/YYYY 的创建屏幕中添加日期。
有关如何执行此操作的任何线索......即将新日期转换为 MM/DD/YYYY ....
for(int i=0;i<rowcount;i++)
{
String datetext = lastdate.get(i).getText();
//Specifying date format that matches the given date
SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat outputDateFormat = new SimpleDateFormat("MM/dd/yyyy");
Calendar c = Calendar.getInstance();
try {
//Setting the date to the given date
c.setTime(inputDateFormat.parse(datetext));- datetext - will take the date from the last row of the table which is 2000-04-15.
} catch(ParseException e) {
e.printStackTrace();
}
//Number of Days to add
int daysToIncrement = 10;
c.add(Calendar.DATE, daysToIncrement);
//Date after adding the days to the given date
String newDate = outputDateFormat.format(c.getTime());
System.out.println("Get the New Date:"+newDate);
以下是我完成的步骤: 我已阅读 table 并在最后一行取了日期 - 日期为 YYY-MM-DD 日期增加 10,并以 YYY-MM-DD 格式显示结果。 但我的问题是我需要以 MM/DD/YYYY 格式输入日期,但我不确定该怎么做 下面是我的代码: 列出最后日期 = driver.findElements(By.xpath("(//table[包含(@class,'mat-table')]//tr/td[5] )[最后的()]”)); int rowcount = lastdate.size(); System.out.println("获取行数:"+rowcount);
for(int i=0;i<rowcount;i++)
{
String datetext = lastdate.get(i).getText();
//Specifying date format that matches the given date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
try{
//Setting the date to the given date
c.setTime(sdf.parse(datetext));- datetext - will take the date from the last row of the table which is 2000-04-15.
}catch(ParseException e){
e.printStackTrace();
}
//Number of Days to add
int daysToIncrement = 10;
c.add(Calendar.DATE, daysToIncrement);
//Date after adding the days to the given date
String newDate = sdf.format(c.getTime());
System.out.println("Get the New Date:"+newDate);
}
当我打印结果时 - 它显示日期为 2000-04-25
但我需要在 MM/DD/YYYY 的创建屏幕中添加日期。 有关如何执行此操作的任何线索......即将新日期转换为 MM/DD/YYYY ....
for(int i=0;i<rowcount;i++)
{
String datetext = lastdate.get(i).getText();
//Specifying date format that matches the given date
SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat outputDateFormat = new SimpleDateFormat("MM/dd/yyyy");
Calendar c = Calendar.getInstance();
try {
//Setting the date to the given date
c.setTime(inputDateFormat.parse(datetext));- datetext - will take the date from the last row of the table which is 2000-04-15.
} catch(ParseException e) {
e.printStackTrace();
}
//Number of Days to add
int daysToIncrement = 10;
c.add(Calendar.DATE, daysToIncrement);
//Date after adding the days to the given date
String newDate = outputDateFormat.format(c.getTime());
System.out.println("Get the New Date:"+newDate);