from time import * #匯入模組
print(localtime()) #獲取本地時間元組
print(asctime(localtime())) #返回本地時間
print(strftime(』%y-%m-%d %h:%m:%s』)) #修改時間格式
#獲取當前日期
import time
print(time.localtime().tm_year,』-』,time.localtime().tm_mon,』-』,time.localtime().tm_mday)
year_cur = time.localtime().tm_year
month_cur =time.localtime().tm_mon
day_cur =time.localtime().tm_mday
import time
print(time.localtime().tm_year,』-』,time.localtime().tm_mon,』-』,time.localtime().tm_mday,』\n』,time.localtime().tm_hour,』:』,time.localtime().tm_min,』:』,time.localtime().tm_sec)
print(time.localtime().tm_year,』-』,time.localtime().tm_mon,』-』,time.localtime().tm_mday,』 『,time.localtime().tm_hour,』:』,time.localtime().tm_min,』:』,time.localtime().tm_sec)
注意點:
from time import * 從time包中匯入所有函式,匯入後相當於本地函式,可以直接呼叫
import time 匯入time,呼叫包中函式需要用 time.函式名
(簡單說:import tome 後面語句要加time.
from time import *後面語句不需要加time.)
Python 獲得系統時間
取得時間相關的資訊的話,要用到python time模組,python time模組裡面有很多非常好用的功能,你可以去官方文件了解下,要取的當前時間的話,要取得當前時間的時間戳,時間戳好像是1970年到現在時間相隔的時間。你可以試下下面的方式來取得當前時間的時間戳 import time print...
獲得本地IP
一些定義 hostent declare struct hostent struct in addr s un b struct s un w u long s addr s un define s addr s un.s addr can be used for most tcp ip code ...
Python時間獲得及格式轉換
常用的匯入模組常用的格式 import os import 我們一般用來匯入模組,常用的快捷鍵是alt enter可以直接匯入模組 from math import floor 從什麼模組中匯入什麼,最終可以匯入乙個函式,或者乙個類,再或者是乙個模組 也就是一層一層的呼叫 注意 1 import後面...