0

私はこのサイトを初めて使用し、Selenium と Java を初めて使用します。5 項目のドロップダウン リスト内に保存されているオプションが、今日の日付から 1 ずつ減少することを確認するコードを作成しようとしています。したがって、最初のオプションは昨日の日付、2 番目は 2 日前、3 番目は 3 日前などです。その日が月曜日の場合、日付は前の金曜日である必要があることを考慮してください。

よろしくお願いします:-)

4

2 に答える 2

0
public static String getDate(int daysBefore) {
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); // For formating the date
        // Or if you're american:           ("MM/dd/yyyy")
        Calendar calendar = Calendar.getInstance(); // Create a calendar
        calendar.add(Calendar.DATE, -daysBefore); // Put it back however may days specified
        return df.format(calendar.getTime()); // Format it
    }

引数「daysBefore」は、何日前に取得するかを指定します。したがって、getDate(1) は昨日を返し、getDate(2) は数日前を返します。

于 2013-09-01T13:02:16.593 に答える