㈠ python3 pycurl 能獲取伺服器處理時間嗎
改寫 python 的同時,考慮腳本的靈活性准備增加兩個參數,第一個是請求測試次數,第二個是請求測試的 URL,而 python 默認提供了argparse 庫,可以很方便的生成 --help 的幫助和解析傳遞的參數!
㈡ python怎麼輸入日期
"%Y - %m - %d"不能有空格,如果是python3,把raw_input改成input。
#-*-coding:UTF-8-*-
importtime
importdatetime
a=raw_input('請輸入日期,格式為yyyy-mm-dd')
t=time.strptime(a,"%Y-%m-%d")
y,m,d=t[0:3]
print(datetime.datetime(y,m,d))
㈢ 怎麼將python時間段(Timedelta)轉化為int或float數值形式! 急。
1、打開visio studio 2015,在文件中打開新建項目,新建一個Python應用程序,並修改程序的名稱為int2date。
㈣ Python3 新手求助 如何處理中文日期 O(∩_∩)O謝謝
用re
importre
text=r'6月14日'
pat=r'd+'
results=re.findall(pat,text)
month,day=results
㈤ python3 環境,如何計算時間的比較和加減
顯示5分鍾前的時間
print(datetime.datetime.now()-datetime.timedelta(seconds=5*60))
構造時間並顯示時間差
d=datetime.datetime.now()
d=d.replace(hour=9,minute=30,second=0)
print((datetime.datetime.now()-d))
㈥ python如何獲取三個小時之前的時間並輸出
python獲取三個小時之前的時間的方法:
1、使用「import datetime」導入datetime包
2、用「now()」函數得到的當前時間減去三個小時,輸出這個結果就可以了
執行結果如下:
更多Python知識,請關註:Python自學網!!
㈦ 為什麼python3.4寫根據年月日得出日期的程序會出現month-name未定義
不應該,下面是一個例子
>>>importdatetime
>>>datetime.date(2015,12,25).strftime("%Y/%m/%d")
'2015/12/25'
>>>
㈧ python3有沒有時間控制項
#-*- coding:utf-8 -*-
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("file:///C:/Users/hunk/Desktop/bootstrap-datetimepicker/bootstrap-datetimepicker/demo/index.html")
js = "$('input:eq(0)').removeAttr('readonly')" # jQuery,移除屬性
# js = "$('input:eq(0)').attr('readonly',false)" # jQuery,設置為false
driver.execute_script(js)
input_datetime = driver.find_element_by_xpath('/html/body/div[1]/form/fieldset/div/div[1]/input[1]')
input_datetime.send_keys("2017-09-21")
input_datetime.click()
time.sleep(5)
driver.quit()
調用execute_script方法來執行js,來處理時間控制項,然後我們可以直接輸入日期。
㈨ python datetime處理時間
python時間處理方法datetime(),下面就舉幾個代碼案例進行說明,代碼如下:
#-*-coding:utf-8-*-
#運行環境:Python3.4
#datetime類
#datetime是date與time的結合體,包括date與time的所有信息。
#它的構造函數如下:
#datetime.datetime(year,month,day[,hour[,minute[,second[,microsecond[,tzinfo]]]]])
#各參數的含義與date、time的構造函數中的一樣,要注意參數值的范圍。
#1.datetime類定義的類屬性與方法:
#datetime.min、datetime.max:datetime所能表示的最小值與最大值;
#print:datetime.max:9999-12-3123:59:59.999999
#print:datetime.min:0001-01-0100:00:00
fromdatetimeimport*
importtime
print('datetime.max:'+str(datetime.max))
print('datetime.min:'+str(datetime.min))
#datetime.resolution:datetime最小單位;
#print:datetime.resolution:0:00:00.000001
print('datetime.resolution:'+str(datetime.resolution))
#datetime.today():返回一個表示當前本地時間的datetime對象;
#print:today():2012-09-1219:37:50.721000
print('today():'+str(datetime.today()))
#datetime.now([tz]):返回一個表示當前本地時間的datetime對象,如果提供了參數tz,則獲取tz參數所指時區的本地時間;
#print:now():2012-09-1219:37:50.738000
print('now():'+str(datetime.now()))
#datetime.utcnow():返回一個當前utc時間的datetime對象;
#print:2012-09-1211:37:50.739000
print('utcnow():'+str(datetime.utcnow()))
#datetime.fromtimestamp(timestamp[,tz]):根據時間戮創建一個datetime對象,參數tz指定時區信息;
#print:fromtimestamp(tmstmp):2012-09-1219:37:50.741000
print('fromtimestamp(tmstmp):'+str(datetime.fromtimestamp(time.time())))
#datetime.utcfromtimestamp(timestamp):根據時間戮創建一個datetime對象;
#print:utcfromtimestamp(tmstmp):2012-09-1211:37:50.742000
print('utcfromtimestamp(tmstmp):'+str(datetime.utcfromtimestamp(time.time())))
#datetime.combine(date,time):根據date和time,創建一個datetime對象;
#print:datetime.combine(date,time):2012-09-1219:46:05
d=date(2012,9,12)
fromdatetimeimport*
t=time(19,46,5)
print('datetime.combine(date,time):'+str(datetime.combine(d,t)))
#datetime.strptime(date_string,format):將格式字元串轉換為datetime對象;
#print:2007-03-0421:08:12
print(datetime.strptime("2007-03-0421:08:12","%Y-%m-%d%H:%M:%S"))
#2.datetime類提供的實例方法與屬性
dt=datetime.strptime("2012-09-1221:08:12","%Y-%m-%d%H:%M:%S")
#print:2012912218120None
print(dt.year)
print(dt.month)
print(dt.day)
print(dt.hour)
print(dt.minute)
print(dt.second)
print(dt.microsecond)
print(dt.tzinfo)
print(dt.date())
print(dt.time())
print(dt.replace(year=2013))
print(dt.timetuple())
print(dt.utctimetuple())
print(dt.toordinal())
print(dt.weekday())
print(dt.isocalendar())
#printdt.isoformat([sep])
#datetime.ctime():返回一個日期時間的C格式字元串,等效於time.ctime(time.mktime(dt.timetuple()));
#3.格式字元串
#datetime.strftime(format)
#%a星期的簡寫。如星期三為Web
#%A星期的全寫。如星期三為Wednesday
#%b月份的簡寫。如4月份為Apr
#%B月份的全寫。如4月份為April
#%c:日期時間的字元串表示。(如:04/07/1010:43:39)
#%d:日在這個月中的天數(是這個月的第幾天)
#%f:微秒(范圍[0,999999])
#%H:小時(24小時制,[0,23])
#%I:小時(12小時制,[0,11])
#%j:日在年中的天數[001,366](是當年的第幾天)
#%m:月份([01,12])
#%M:分鍾([00,59])
#%p:AM或者PM
#%S:秒(范圍為[00,61],為什麼不是[00,59],參考python手冊~_~)
#%U:周在當年的周數當年的第幾周),星期天作為周的第一天
#%w:今天在這周的天數,范圍為[0,6],6表示星期天
#%W:周在當年的周數(是當年的第幾周),星期一作為周的第一天
#%x:日期字元串(如:04/07/10)
#%X:時間字元串(如:10:43:39)
#%y:2個數字表示的年份
#%Y:4個數字表示的年份
#%z:與utc時間的間隔(如果是本地時間,返回空字元串)
#%Z:時區名稱(如果是本地時間,返回空字元串)
#%%:%%=>%
dt=datetime.now()
#print:(%Y-%m-%d%H:%M:%S%f):2012-09-1223:04:27145000
print('(%Y-%m-%d%H:%M:%S%f):'+str(dt.strftime('%Y-%m-%d%H:%M:%S%f')))
#print:(%Y-%m-%d%H:%M:%S%p):12-09-1211:04:27PM
print('(%Y-%m-%d%H:%M:%S%p):'+str(dt.strftime('%y-%m-%d%I:%M:%S%p')))
#print:%a:Wed
print('%%a:%s'%dt.strftime('%a'))
#print:%A:Wednesday
print('%%A:%s'%dt.strftime('%A'))
#print:%b:Sep
print('%%b:%s'%dt.strftime('%b'))
#print:%B:September
print('%%B:%s'%dt.strftime('%B'))
#print:日期時間%c:09/12/1223:04:27
print('日期時間%%c:%s'%dt.strftime('%c'))
#print:日期%x:09/12/12
print('日期%%x:%s'%dt.strftime('%x'))
#print:時間%X:23:04:27
print('時間%%X:%s'%dt.strftime('%X'))
#print:今天是這周的第3天
print('今天是這周的第%s天'%dt.strftime('%w'))
#print:今天是今年的第256天
print('今天是今年的第%s天'%dt.strftime('%j'))
#print:今周是今年的第37周
print('今周是今年的第%s周'%dt.strftime('%U'))
上面代碼案例運行結果如下:
atetime.max:9999-12-3123:59:59.999999
datetime.min:0001-01-0100:00:00
datetime.resolution:0:00:00.000001
today():2014-05-0415:58:18.141186
now():2014-05-0415:58:18.193146
utcnow():2014-05-0407:58:18.243958
fromtimestamp(tmstmp):2014-05-0415:58:18.291558
utcfromtimestamp(tmstmp):2014-05-0407:58:18.342550
datetime.combine(date,time):2012-09-1219:46:05
2007-03-0421:08:12
2012
9
12
21
8
12
0
None
2012-09-12
21:08:12
2013-09-1221:08:12
time.struct_time(tm_year=2012,tm_mon=9,tm_mday=12,tm_hour=21,tm_min=8,tm_sec=12,tm_wday=2,tm_yday=256,tm_isdst=-1)
time.struct_time(tm_year=2012,tm_mon=9,tm_mday=12,tm_hour=21,tm_min=8,tm_sec=12,tm_wday=2,tm_yday=256,tm_isdst=0)
734758
2
(2012,37,3)
(%Y-%m-%d%H:%M:%S%f):2014-05-0415:58:19326295
(%Y-%m-%d%H:%M:%S%p):14-05-0403:58:19PM
%a:Sun
%A:Sunday
%b:May
%B:May
日期時間%c:SunMay415:58:192014
日期%x:05/04/14
時間%X:15:58:19
今天是這周的第0天
今天是今年的第124天
今周是今年的第18周
㈩ python3 時間轉換
安裝pytz模塊,看不懂你的例子
importdatetime
importpytz
gmt=pytz.timezone('GMT')
eastern=pytz.timezone('US/Eastern')
time="Tue,12Jun201214:03:10GMT"
date=datetime.datetime.strptime(time,'%a,%d%b%Y%H:%M:%SGMT')
printdate
dategmt=gmt.localize(date)
printdategmt
dateeastern=dategmt.astimezone(eastern)
printdateeastern