开发者

How to check day in android? [duplicate]

开发者 https://www.devze.com 2023-04-04 02:12 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: What is the easiest way to get the current day of the week in Android?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

What is the easiest way to get the current day of the week in Android?

I want to make an app with the question: "Is it al Friday?" And than you would see 开发者_如何学Python"No" or "Yes" if it's Friday. So my question is: How can i check if today it's friday? I hope you understand me, otherwise just ask me.

Gaauwe


You should use the java.util.Calendar class.

Quoting the documentation :

Calendar rightNow = Calendar.getInstance();
if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY){
   //do some stuff here
}


see this: http://developer.android.com/reference/java/util/Date.html u probably want to create a calendar instance & set it to the current date and get the day of the week(Calendar.DAY_OF_WEEK) & compare with friday(friday = 6 if i remember correctly?,check on this pls) or use new date()....


Simply this:

    private boolean isTodayFriday(){
    Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号