0

在我的应用程序中,我正在获取即将到来的生日列表,但面临一个小问题,没有在列表中获取当前日期 b'days,请参阅我编写的代码以获取即将到来的生日:

public static void requestFriends(FacebookRequest facebookRequest) 
    {
        Log.d(LOG_TAG, "requestFriends(" + ")");
        // ----- [start]to get all upcoming birthdays using Variables -----
        Calendar cal = Calendar.getInstance();
        Date today = cal.getTime();
        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd");
        String today_formatted = formatter.format(today);
        String query = "select name, birthday, uid, pic_square FROM user " +
        "WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND birthday_date != 'null' " +
        "AND birthday_date >= '" + today_formatted + "'ORDER BY birthday_date ASC";
        // ----- [end]to get all upcoming birthdays using Variables -----       

        Bundle params = new Bundle();
        params.putString("method", "fql.query");
        params.putString("query", query);
        FacebookUtility.asyncRunner.request(null, params, new FacebookRequestListener(FacebookRequestListener.FRIENDS, facebookRequest));   
    }

所以告诉我我在哪里失踪,我不知道如何在列表中获取今天的生日....

4

1 回答 1

0

同一天我找到了解决方案,但有点忙,所以为了得到 Current Date b'days 而不是在逻辑中使用今天的日期,我使用的是昨天的日期,我在我的代码中做了一些更改,见下文:

Calendar cal = Calendar.getInstance();
        Date today = cal.getTime();
        Date oneDayBefore = new Date(today.getTime() - 10);         
        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd");
        String today_formatted = formatter.format(oneDayBefore);
        String query = "select name, birthday, uid, pic_square FROM user " +
        "WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND birthday_date != 'null' " +
        "AND birthday_date > '" + today_formatted + "'ORDER BY birthday_date ASC";

通过使用上面的代码,您可以获得当前日期 b'days 以及所有即将到来的 Facebook 朋友的生日,甚至更多只需使用 >= this 代替 > 来获取您朋友过去一天的生日

于 2013-11-08T11:20:31.393 回答