取得指定日期是星期幾

2021-07-16 18:32:06 字數 567 閱讀 9016

a、使用calendar類

//根據日期取得星期幾

public static string getweek(date date);

calendar cal = calendar.getinstance();

cal.settime(date);

int week_index = cal.get(calendar.day_of_week) - 1;

if(week_index<0)

return weeks[week_index];

}

b、使用******dateformat類

//根據日期取得星期幾

public static string getweek(date date)

注:格式化字串存在區分大小寫

對於建立******dateformat傳入的引數:eeee代表星期,如「星期四」;mmmm代表中文月份,如「十一月」;mm代表月份,如「11」;

yyyy代表年份,如「2010」;dd代表天,如「25」

獲取指定日期為星期幾

之前在專案開發過程當中,需要寫乙個月曆和乙個週曆,由於當時專案經驗太少,儲存時間的時候將格式化後的時間儲存到資料庫,並且還要判斷當前乙個月內所有天數里發生的事件,還用到了給出指定的日期判斷是星期幾的功能。所以,對後期時間處理造成了不必要的麻煩。1.2.功能 獲取指定年月日是星期幾 3.傳參 年月日格...

js獲取指定日期週數以及星期幾

js獲取日期時遇到如下需求,根據某年某周獲取一周的日期。如開始日期規定為星期四到下一周的星期五為一周。如下 function getnowformatdate thedate else if day 10 else return currentdate function isinoneyear ye...

取得日期的星期

取得日期的星期 create function getweekcn date datetime 程式功能 取得日期的星期 引數 date 日期 呼叫方法 select dbo.getweekcn getdate returns varchar 6 as begin declare strreturn...