---
title: "获取当前是星期几"
author: "zheyiw"
date: "2012-12-20T16:58:17Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2012-12-20T16:58:17Z"
id: 1751187
url: "https://zheyiw.iteye.com/blog/1751187"
---

```java

public static int getWeekOfDate(Date dt) {
		int[] weekDays = { 7, 1, 2, 3, 4, 5, 6 };
		//String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
		Calendar cal = Calendar.getInstance();
		cal.setTime(dt);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	public static int getWeekOfDate(Calendar cal) {
		int[] weekDays = { 7, 1, 2, 3, 4, 5, 6 };
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	public static int getWeekOfDate(long time) {
		int[] weekDays = { 7, 1, 2, 3, 4, 5, 6 };
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(time);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}


```