> Erlang中文手册 > day_of_the_week/1 计算某天是星期几

calendar:day_of_the_week/1

计算某天是星期几

用法:

day_of_the_week(Date) -> daynum()

内部实现:

%% day_of_the_week(Year, Month, Day)
%% day_of_the_week({Year, Month, Day})
%%
%% Returns: 1 | .. | 7. Monday = 1, Tuesday = 2, ..., Sunday = 7.
%%
-spec day_of_the_week(Year, Month, Day) -> daynum() when
      Year :: year(),
      Month :: month(),
      Day :: day().
day_of_the_week(Year, Month, Day) ->
    (date_to_gregorian_days(Year, Month, Day) + 5) rem 7 + 1.

-spec day_of_the_week(Date) -> daynum() when
      Date:: date().
day_of_the_week({Year, Month, Day}) ->
    day_of_the_week(Year, Month, Day).

这个函数计算给出的 Year 年 Month 月 Day 日是星期几,返回的值表示星期的天数,例如 1 表示星期天、2表示星期一、...7表示星期六等等。

calendar:day_of_the_week({2003, 10, 15}).