在selenium webdriver中添加日期格式MM / dd / yyyy

时间:2015-11-06 15:03:32

标签: java selenium

问题很简单,如何为这种日期格式添加天数:

MM / dd / yyyy喜欢11/06/2015

1 个答案:

答案 0 :(得分:1)

您可以这样做:

    String format = "mm/dd/yyyy";
    String date = "11/06/2015";
    SimpleDateFormat simpleFormat = new SimpleDateFormat("mm/dd/yyyy");

    java.text.DateFormat df = new java.text.SimpleDateFormat(format);
    java.util.Calendar calendar = java.util.Calendar.getInstance();

    try {
        calendar.setTime(df.parse(date));
        calendar.add(java.util.Calendar.DAY_OF_MONTH, +1);
        String formatted = simpleFormat.format(calendar.getTime());
        System.out.println(formatted);
    } catch (Exception ex) {
        System.out.println("Error: " + ex.toString());
    }