2

ローカル日付 (JODA TIME) API から週の日付のみを取得する方法を探していますか? この形式でコードを記述しようとしています..

LocalDate today = new LocalDate();
LocalDate getDate = new LocalDate(sqlDate);// i will recieve sqldate from sql table

//if the getdate and number of days to remind is equals to today 
//and if it is between monday to friday ,send an email. 
//ReminderDays is an integer
if(getDate+ReminderDays == today)
SendMail();

可能であれば、コードを提供してください? ありがとうございました。

4

3 に答える 3

3

次のことができます

1) getDate に日数を追加して、newDate を取得します。

2) 今日の日付と比較する

3) true の場合 getDayOfWeek()、@joe で指定されたメソッドを使用して、1 と 5 の間であるかどうかを確認し、send mail メソッドを呼び出すことができます。

擬似コード:

LocalDate getDate = new LocalDate(sqlDate);
LocalDate newDate =getDate.plusDays(int days) ;
if(compare newDate & todays date)
//if true then do
if(1<=newDate.getDayOfWeek()<=5)
//call send mail
于 2013-03-11T12:02:57.120 に答える
2

次のように値を返すgetDayOfWeek()というメソッドがあります

    public static final int MONDAY = 1;
    public static final int TUESDAY = 2;
    public static final int WEDNESDAY = 3;
    public static final int THURSDAY = 4;
    public static final int FRIDAY = 5;
    public static final int SATURDAY = 6;
    public static final int SUNDAY = 7;
于 2013-03-11T11:47:16.533 に答える
0

整数値ではなく定数を使用する場合。

Joda は DateTimeConstants の値を使用します。これらは ISO8601 定数です。

ソースコードはこちら:

http://joda-time.sourceforge.net/apidocs/src-html/org/joda/time/DateTimeConstants.html#line.70

使用法は次のようになります。

// Joda uses MONDAY=1 to SUNDAY=7
if (startDate.getDayOfWeek() < DateTimeConstants.SATURDAY) {
    doMyWeekdayThang();
}
于 2017-01-05T11:35:03.640 に答える