当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Elixir Calendar.ISO.day_of_week用法及代码示例


Elixir语言中 Calendar.ISO.day_of_week 相关用法介绍如下。

用法:

day_of_week(year, month, day, starting_on)
(从 1.11.0 开始)
@spec day_of_week(year(), month(), day(), :default | weekday()) ::
  {day_of_week(), 1, 7}

根据给定的 yearmonthday 计算星期几。

它是一个从 1 到 7 的整数,其中 1 是给定的 starting_on 工作日。例如,如果 starting_on 设置为 :monday ,则 1 是星期一,7 是星期日。

starting_on 也可以是 :default ,相当于 :monday

例子

iex> Calendar.ISO.day_of_week(2016, 10, 31, :monday)
{1, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 1, :monday)
{2, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 2, :monday)
{3, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 3, :monday)
{4, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 4, :monday)
{5, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 5, :monday)
{6, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 6, :monday)
{7, 1, 7}
iex> Calendar.ISO.day_of_week(-99, 1, 31, :monday)
{4, 1, 7}

iex> Calendar.ISO.day_of_week(2016, 10, 31, :sunday)
{2, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 1, :sunday)
{3, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 2, :sunday)
{4, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 3, :sunday)
{5, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 4, :sunday)
{6, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 5, :sunday)
{7, 1, 7}
iex> Calendar.ISO.day_of_week(2016, 11, 6, :sunday)
{1, 1, 7}
iex> Calendar.ISO.day_of_week(-99, 1, 31, :sunday)
{5, 1, 7}

iex> Calendar.ISO.day_of_week(2016, 10, 31, :saturday)
{3, 1, 7}

相关用法


注:本文由纯净天空筛选整理自elixir-lang.org大神的英文原创作品 Calendar.ISO.day_of_week(year, month, day, starting_on)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。