LoginSignup
22
22

More than 5 years have passed since last update.

色んな言語における曜日の数値表現

Last updated at Posted at 2014-03-13

とりあえず使用頻度の高い言語だけピックアップ。
意外とバラバラですね。
ISO 8601由来とtime.h由来のパターンは理解できますが、それ以外はどうしてこうなったのか…。

言語/ツール [1-7]=[月-日] [0-6]=[日-土] [0-6]=[月-日] [1-7]=[日-土]
ISO 8601 D
SWI-Prolog day_of_the_week/2
Python date.isoweekday()
Python datetime.isoweekday()
Ruby Date#cwday
Ruby Date#wday
JavaScript Date.getDay
C/C++ (time.h) tm_wday
CRONTAB (5) day of week
SRFI date-week-day
Python date.weekday()
Python datetime.weekday()
Java java.util.Calendar

ISO 8601

D

D は曜日を表し、月曜日が 1、日曜日は 7 である。「8」「9」は表記数値とされない(エラー扱い)。
http://ja.wikipedia.org/wiki/ISO_8601#.E5.B9.B4.E3.81.A8.E9.80.B1.E3.81.A8.E6.9B.9C.E6.97.A5

SWI-Prolog

day_of_the_week/2

Days of the week are numbered from one to seven: monday = 1, tuesday = 2, ..., sunday = 7.
http://www.swi-prolog.org/pldoc/doc_for?object=date:day_of_the_week/2

Python

date.isoweekday()

月曜日を 1,日曜日を 7 として、曜日を整数で返します。
http://docs.python.jp/3/library/datetime.html#date-objects

datetime.isoweekday()

月曜日を 1、日曜日を 7 として、曜日を整数で返します。
http://docs.python.jp/3/library/datetime.html#datetime-objects

Ruby

Date#cwday

cwday -> Integer
暦週の日 (曜日) を返します (1-7、月曜は1)。
http://docs.ruby-lang.org/ja/2.1.0/method/Date/i/cwday.html

Date#wday

wday -> Integer
曜日を返します (0-6、日曜日は零)。
http://docs.ruby-lang.org/ja/2.1.0/class/Date.html#I_WDAY

JavaScript

Date.getDay

日曜日が 0、月曜日が 1、火曜日が 2、という対応です。
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay

C/C++ (time.h)

tm_wday

days since Sunday – [0, 6]
http://en.cppreference.com/w/c/chrono/tm

CRONTAB(5)

day of week

day of week 0-7 (0 or 7 is Sun, or use names)
http://www.unix.com/man-page/linux/5/crontab/

SRFI (Scheme Requests for Implementation) 19

date-week-day date -> integer

The day of the week of this date, where Sunday=0, Monday=1, etc.
http://srfi.schemers.org/srfi-19/srfi-19.html

Python

date.weekday()

月曜日を 0、日曜日を 6 として、曜日を整数で返します。
http://docs.python.jp/3/library/datetime.html#date-objects

datetime.weekday()

月曜日を 0、日曜日を 6 として、曜日を整数で返します。
http://docs.python.jp/3/library/datetime.html#datetime-objects

Java

java.util.Calendar

public static final int SUNDAY 1
http://docs.oracle.com/javase/jp/7/api/constant-values.html#java.util.Calendar.SUNDAY

22
22
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
22
22