時間:書式
言語、ライブラリで使われる時間の書式
https://docs.google.com/spreadsheets/d/1GeKU0OHoveM76iL0xEUXP6YPZoDwUSWtN4gfZFt8ey0/edit?usp=sharing
プログラミング言語、ライブラリによって、かなり違いがあるため、移植や別言語の導入の際に問題となりやすい。(変換忘れ、思い込みによる誤記)
要注意な点
00:00 を 24:00とするか(普通はないはず)
00:00 を 00:00AM(素直な実装)とするか、12:00PM(普通はないはず)とするか
12:00 を 00:00PM(素直な実装)とするか、12:00AM(普通はないはず)とするか
基本的には以下のような流れで書式化されるはず
時刻→カレンダー型構造体への分解→各フィールドの表示
C言語
strftime
https://pubs.opengroup.org/onlinepubs/9799919799/functions/strftime.html
https://linuxjm.osdn.jp/html/LDP_man-pages/man3/strftime.3.html
シェルスクリプト
date コマンド
C言語とほぼ同じ
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/date.html
http://linuxjm.osdn.jp/html/GNU_coreutils/man1/date.1.html
https://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html#date-invocation
JavaScript
そもそも標準のフォーマッタがない。
標準の時刻型は Date クラス
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date
標準的な書式はある。
ISO 8601形式
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
RFC-1123(RFC-822)形式
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString
サードパーティーのライブラリ
moment.js
https://momentjs.com
https://momentjs.com/docs/#/displaying/format/
Date-Utils
https://jerrysievert.github.io/date-utils/index.html
js-joda (Java JSR 310 の移植)
https://js-joda.github.io/js-joda/
Java
JSR 310: Date and Time API
https://jcp.org/en/jsr/detail?id=310
java.time.format package
https://docs.oracle.com/javase/8/docs/api/java/time/format/package-summary.html
DateTimeFormatter (今はこれを使う)
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
SimpleDateFormat (もう使うべきではない)
https://docs.oracle.com/javase/jp/8/docs/api/java/text/SimpleDateFormat.html
Python
C言語とほぼ同じ
https://docs.python.org/ja/3/library/datetime.html
Ruby
C言語とほぼ同じ
https://docs.ruby-lang.org/ja/latest/method/Time/i/strftime.html
PHP
date
https://www.php.net/manual/ja/function.date.php
.NET Framework
標準の日時書式指定文字列
https://docs.microsoft.com/ja-jp/dotnet/standard/base-types/standard-date-and-time-format-strings
カスタム日時形式文字列
https://docs.microsoft.com/ja-jp/dotnet/standard/base-types/custom-date-and-time-format-strings
VBA
https://docs.microsoft.com/ja-jp/office/vba/language/reference/user-interface-help/format-function-visual-basic-for-applications
Excel
https://support.microsoft.com/ja-jp/office/日付または時刻として数値の書式を設定する-418bd3fe-0577-47c8-8caa-b4d30c528309
機械翻訳で誤訳があることに注意
英語
https://support.microsoft.com/en-us/office/format-numbers-as-dates-or-times-418bd3fe-0577-47c8-8caa-b4d30c528309?ui=en-us&rs=en-us&ad=us
Google スプレッドシート(Google spreadsheet)
TEXT関数
https://support.google.com/docs/answer/3094139?hl=ja&sjid=3493045696696343170-AP
PostgreSQL
https://www.postgresql.jp/document/12/html/functions-formatting.html
MySQL
https://dev.mysql.com/doc/refman/5.6/ja/date-and-time-functions.html
Oracle
書式モデル
https://docs.oracle.com/cd/E16338_01/server.112/b56299/sql_elements004.htm
SQLServer
.NET Framework と同じ
https://docs.microsoft.com/ja-jp/sql/t-sql/functions/format-transact-sql?view=sql-server-ver15
Keyword: フォーマット
#時間