有些內容使用中英雙語,有些只有英文或中文。歡迎使用與分享任何內容,但先來信告知並標示此部落格為出處。
Some parts use both Chinese and English, but some parts use only one language. Feel free to share, but please contact me first and list this blog as your reference.

2014年3月29日 星期六

Python 學習小筆記 (三) - Date and Time

Python 學習小筆記 () - Date and Time

Python 學習小筆記 for Codecademy Python



1.        要使用時間需要import datetime 才能用
用法: from datetime import datetime

2.        datetime.now() 表示現在時間
Ex: print datetime.now() à 2014-03-28 15:51:36.039938

也能用變數來存取這個"現在時間"
Ex: now = datetime.now()

3.        datetime.now() 也可以只取出年、月、日、時、分、秒等
Ex: print datetime.now().year   à 2014
Ex: print datetime.now().month  à 3
Ex: print datetime.now().day   à 28
Ex: print datetime.now().hour   à12
Ex: print datetime.now().minute à6
Ex: print datetime.now().second à32


If you want to use (copy, paste or quote) my original article, please contact me through email (autek.roy@gmail.com). If there is any mistake or comment, please let me know. :D

如要使用(複製貼上或轉載)作者原創文章,請來信跟我聯絡 (autek.roy@gmail.com)。如果有發現任何的錯誤與建議請留言或跟我連絡。 : )

沒有留言:

張貼留言

請留下您的任何想法或建議!
Please leave any thought or comment!