python獲取當(dāng)前日期和時(shí)間的方法
本文實(shí)例講述了python獲取當(dāng)前日期和時(shí)間的方法。分享給大家供大家參考。具體如下:
import datetime
# Get a datetime object
now = datetime.datetime.now()
# General functions
print "Year: %d" % now.year
print "Month: %d" % now.month
print "Day: %d" % now.day
print "Weekday: %d" % now.weekday()
# Day of week Monday = 0, Sunday = 6
print "Hour: %d" % now.hour
print "Minute: %d" % now.minute
print "Second: %d" % now.second
print "Microsecond: %d" % now.microsecond
# ISO Functions
print "ISO Weekday: %d" % now.isoweekday()
# Day of week Monday = 1, Sunday = 7
print "ISO Format: %s" % now.isoformat()
# ISO format, e.g. 2010-12-24T07:10:52.458593
print "ISO Calendar: %s" % str(now.isocalendar())
# Tuple of (ISO year, ISO week number, ISO weekday)
# Formatted date
print now.strftime("%Y/%m/%d")
希望本文所述對大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
使用matplotlib中scatter方法畫散點(diǎn)圖
這篇文章主要為大家詳細(xì)介紹了使用matplotlib中scatter方法畫散點(diǎn)圖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-03-03
Jupyter 無法下載文件夾如何實(shí)現(xiàn)曲線救國
這篇文章主要介紹了Jupyter 無法下載文件夾如何實(shí)現(xiàn)曲線救國?今天小編就為大家?guī)砹私鉀Q方法,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
Python實(shí)現(xiàn)解壓當(dāng)天創(chuàng)建的ZIP文件到指定文件夾中
這篇文章主要為大家詳細(xì)介紹了Python如何實(shí)現(xiàn)解壓當(dāng)天創(chuàng)建的ZIP文件到指定文件夾中,文中的示例代碼講解詳細(xì),需要的小伙伴可以參考下2024-03-03
pandas實(shí)現(xiàn)按行遍歷dataframe的方法(itertuples,iterrows)
本文主要介紹了pandas實(shí)現(xiàn)按行遍歷dataframe的方法,主要介紹了兩種itertuples,iterrows,具有一定的參考價(jià)值,感興趣的可以了解一下2023-08-08
Python實(shí)現(xiàn)連接postgresql數(shù)據(jù)庫的方法分析
這篇文章主要介紹了Python實(shí)現(xiàn)連接postgresql數(shù)據(jù)庫的方法,結(jié)合實(shí)例形式分析了Python基于psycopg2和python3-postgresql鏈接postgresql數(shù)據(jù)庫的相關(guān)操作技巧,需要的朋友可以參考下2017-12-12
基于Python實(shí)現(xiàn)開發(fā)釘釘通知機(jī)器人
在項(xiàng)目協(xié)同工作或自動(dòng)化流程完成時(shí),我們需要用一定的手段通知自己或他人。Telegram 非常好用,幾個(gè)步驟就能創(chuàng)建一個(gè)機(jī)器人,可惜在國內(nèi)無法使用。所以本文就來開發(fā)一個(gè)釘釘通知機(jī)器人吧2023-02-02
python中ransac算法擬合圓的實(shí)現(xiàn)
RANSAC是一種用于從包含異常數(shù)據(jù)的樣本數(shù)據(jù)集中計(jì)算數(shù)學(xué)模型參數(shù)的算法,本文主要介紹了python中ransac算法擬合圓的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2025-01-01

