Skip to Content
Pythonクイックリファレンス 第4版
book

Pythonクイックリファレンス 第4版

by Alex Martelli, Anna Martelli Ravenscroft, Steve Holden, Paul McGuire, 鈴木 駿, 株式会社クイープ
June 2024
Intermediate to advanced
864 pages
12h 14m
Japanese
O'Reilly Japan, Inc.
Content preview from Pythonクイックリファレンス 第4版

13章時間の操作

Pythonプログラムでは、時間をさまざまな方法で処理できる。時間は秒単位の浮動小数点数で表される(秒の小数部は時間の小数部である)。秒単位の時間を表す引数を受け取る標準ライブラリの関数はすべて、その引数の値として浮動小数点数を受け取る。時刻は、エポック(epoch)と呼ばれる元期からの秒数で表される(エポックは言語やプラットフォームによって異なるが、Pythonのエポックはプラットフォームに関係なく協定世界時[UTC]の1970年1月1日午前0時である)。I/Oが目的の場合は特にそうだが、年、月、日、時、分、秒など、複数の単位の組み合わせで時刻を表現しなければならないこともよくある。もちろん、I/Oが目的の場合は、時刻と日付をヒューマンリーダブルな文字列としてフォーマットしたり、文字列フォーマットから解析したりする能力も必要となる。

13.1 timeモジュール

timeモジュールは、このモジュールがインストールされるシステムのCライブラリに多少依存しており、それにより、timeモジュールが扱うことができる日付の範囲が決まる。古いUnixシステムでは、1970年と2038年が代表的なカットオフポイント†1とされていた(この制限は、次節で説明するdatetimeモジュールを使うことで回避できる)。通常、時刻は協定世界時(UTC、かつてはグリニッジ標準時[GMT]と呼ばれていた)で指定される。timeモジュールはローカルタイムゾーンと夏時間(DST)もサポートしているが、そのシステムのCライブラリがサポートしている範囲に限定される†2。

エポック秒の代わりに、時刻はタイムタプル(timetuple)と呼ばれる9つの整数からなるタプル(表13-1)で表すことができる。タプルの要素はすべて整数である。つまり、タイムタプルは秒の小数部を追跡しない。タイムタプルは ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

並行プログラミング入門 ―Rust、C、アセンブリによる実装からのアプローチ

並行プログラミング入門 ―Rust、C、アセンブリによる実装からのアプローチ

高野 祐輝

Publisher Resources

ISBN: 9784814400812Publisher Website