คำตอบที่ได้รับเลือกจากเจ้าของกระทู้
ความคิดเห็นที่ 1
>
> เหตุใดผลที่ได้ถึงไม่เท่ากันครับ?
>
class datetime.datetime
A combination of a date and a time. Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo.
today: 0.00 น. ของวันนี้ ขอขอบคุณจขคห.ที่ 2 ที่ชี้แนะครับ
today: x.xx น. ของวันนี้ (เศษของวินาทีเป็นทศนิยม)
now: x.xx น. ของวันนี้
ที่มาที่ไป
1. ทั้ง datetime.today() และ datetime.now() ต่างก็เรียก time.time()
แล้วแปลงจำนวนวินาที (และของเศษวินาที) ดังกล่าว
ให้เป็นวันปฏิทิน และเวลาโมงยามของวันนั้น
- https://docs.python.org/3/library/datetime.html#datetime.datetime.today
- https://github.com/python/cpython/blob/3.9/Lib/datetime.py#L1726
2. time.time() คืนค่าจำนวน second (และเศษของวินาที) จาก epoch ซึ่งโดยทั่วไปคือ
เที่ยงคืนของวันขึ้นปีใหม่ 1970 ซึ่งเรียกกันว่า unix epoch
https://docs.python.org/3/library/time.html#time.time
Return the time in seconds since the epoch as a floating point number.
> เหตุใดผลที่ได้ถึงไม่เท่ากันครับ?
>
class datetime.datetime
A combination of a date and a time. Attributes: year, month, day, hour, minute, second, microsecond, and tzinfo.
today: x.xx น. ของวันนี้ (เศษของวินาทีเป็นทศนิยม)
now: x.xx น. ของวันนี้
ที่มาที่ไป
1. ทั้ง datetime.today() และ datetime.now() ต่างก็เรียก time.time()
แล้วแปลงจำนวนวินาที (และของเศษวินาที) ดังกล่าว
ให้เป็นวันปฏิทิน และเวลาโมงยามของวันนั้น
- https://docs.python.org/3/library/datetime.html#datetime.datetime.today
- https://github.com/python/cpython/blob/3.9/Lib/datetime.py#L1726
2. time.time() คืนค่าจำนวน second (และเศษของวินาที) จาก epoch ซึ่งโดยทั่วไปคือ
เที่ยงคืนของวันขึ้นปีใหม่ 1970 ซึ่งเรียกกันว่า unix epoch
https://docs.python.org/3/library/time.html#time.time
Return the time in seconds since the epoch as a floating point number.
▼ กำลังโหลดข้อมูล... ▼
แสดงความคิดเห็น
คุณสามารถแสดงความคิดเห็นกับกระทู้นี้ได้ด้วยการเข้าสู่ระบบ
กระทู้ที่คุณอาจสนใจ
อ่านกระทู้อื่นที่พูดคุยเกี่ยวกับ
Python
Open-source Software
การพัฒนา Desktop Application
การพัฒนาซอฟต์แวร์
python datetime
datetime.datetime.today() == datetime.datetime.now()
เหตุใดผลที่ได้ถึงไม่เท่ากันครับ? ทั้งที่ type() ก็เป็นชนิดเดียวกัน
ขอบคุณครับ