1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Android 曜日を取得する方法

Posted at

Androidで曜日を取得する方法です。

.kt
    val calendar: Calendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Tokyo"), Locale.JAPAN);
    val week: Int = calendar.get(Calendar.DAY_OF_WEEK)
    getWeek(week)
.kt
fun getWeek(day: Int): String {
    return when (day) {
        Calendar.SUNDAY -> "(日)"
        Calendar.MONDAY -> "(月)"
        Calendar.TUESDAY -> "(火)"
        Calendar.WEDNESDAY -> "(水)"
        Calendar.THURSDAY -> "(木)"
        Calendar.FRIDAY -> "(金)"
        Calendar.SATURDAY -> "(土)"
        else -> {
            ""
        }
    }
}

calendar.get(Calendar.DAY_OF_WEEK)で曜日をIntで取得できるので、getWeekのような関数を作成して、何曜日か判定してみました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?