Java Code Examples for java.sql.Date#getDay()

The following examples show how to use java.sql.Date#getDay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeFormat.java    From jmessage-android-uikit with MIT License 4 votes vote down vote up
public String getTime() {
    long currentTime = Configs.getReportTime();
    Date date1 = new Date(currentTime);
    Date date2 = new Date(mTimeStamp);
    SimpleDateFormat format = new SimpleDateFormat(mContext.getString(IdHelper.getString(mContext,
            "jmui_time_format_hours")), Locale.CHINA);
    SimpleDateFormat format1 = new SimpleDateFormat(mContext.getString(IdHelper.getString(mContext,
            "jmui_time_format_accuracy")), Locale.CHINA);
    String date = format.format(mTimeStamp);
    int hour = Integer.parseInt(date.substring(0, 2));
    //今天
    if (date1.getDate() - date2.getDate() == 0) {
        if (hour < 6) {
            return mContext.getString(IdHelper.getString(mContext, "jmui_before_dawn")) + " " + date;
        } else if (hour < 12) {
            return mContext.getString(IdHelper.getString(mContext, "jmui_morning")) + " " + date;
        } else if (hour < 18) {
            return mContext.getString(IdHelper.getString(mContext, "jmui_afternoon")) + " " + date;
        } else {
            return mContext.getString(IdHelper.getString(mContext, "jmui_night")) + " " + date;
        }
        //昨天
    } else if (date1.getDate() - date2.getDate() == 1) {
        return mContext.getString(IdHelper.getString(mContext, "jmui_yesterday"));
    } else if (date1.getDay() - date2.getDay() > 0) {
        switch (date2.getDay()) {
            case 1:
                return mContext.getString(IdHelper.getString(mContext, "jmui_monday"));
            case 2:
                return mContext.getString(IdHelper.getString(mContext, "jmui_tuesday"));
            case 3:
                return mContext.getString(IdHelper.getString(mContext, "jmui_wednesday"));
            case 4:
                return mContext.getString(IdHelper.getString(mContext, "jmui_thursday"));
            case 5:
                return mContext.getString(IdHelper.getString(mContext, "jmui_friday"));
            case 6:
                return mContext.getString(IdHelper.getString(mContext, "jmui_saturday"));
            default:
                return mContext.getString(IdHelper.getString(mContext, "jmui_sunday"));
        }
    } else if (date1.getYear() == date2.getYear()) {
        return date2.getMonth() + 1 + mContext.getString(IdHelper.getString(mContext, "jmui_month"))
                + date2.getDate() + mContext.getString(IdHelper.getString(mContext, "jmui_day"));
    } else {
        return format1.format(mTimeStamp);
    }
}