本文整理匯總了Python中time.month方法的典型用法代碼示例。如果您正苦於以下問題:Python time.month方法的具體用法?Python time.month怎麽用?Python time.month使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類time
的用法示例。
在下文中一共展示了time.month方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: saveImage
# 需要導入模塊: import time [as 別名]
# 或者: from time import month [as 別名]
def saveImage():
keepDiskSpaceFree(config.diskSpaceToReserve)
time = datetime.datetime.now()
filenameFull = config.filepath + config.filenamePrefix + "-%04d%02d%02d%02d%02d%02d" % (time.year, time.month, time.day, time.hour, time.minute, time.second)+ "." + config.fileType
# save onto webserver
filename = "/var/www/temp.jpg"
subprocess.call("sudo raspistill -w "+ str(config.saveWidth) +" -h "+ str(config.saveHeight) + " -t 1 -n -vf -e " + config.fileType + " -q 15 -o %s" % filename, shell=True)
print "Captured image: %s" % filename
theSpeech = recognizeFace(filename,filenameFull)
if len(theSpeech)>2:
print theSpeech
saySomething(theSpeech,"en")
config.lookForFaces = 0
# Keep free space above given level
示例2: timestamp_to_float
# 需要導入模塊: import time [as 別名]
# 或者: from time import month [as 別名]
def timestamp_to_float(time):
"""Convert a pandas timestamp to a floating point date.
>>> import datetime
>>> time = datetime.date(2010, 10, 1)
>>> timestamp_to_float(time)
2010.75
>>> time = datetime.date(2011, 4, 1)
>>> timestamp_to_float(time)
2011.25
>>> timestamp_to_float(datetime.date(2011, 1, 1))
2011.0
>>> timestamp_to_float(datetime.date(2011, 12, 1)) == (2011.0 + 11.0 / 12)
True
"""
return time.year + ((time.month - 1) / 12.0)
示例3: julian_day_dt
# 需要導入模塊: import time [as 別名]
# 或者: from time import month [as 別名]
def julian_day_dt(year, month, day, hour, minute, second, microsecond):
"""This is the original way to calculate the julian day from the NREL paper.
However, it is much faster to convert to unix/epoch time and then convert
to julian day. Note that the date must be UTC."""
# Not used anywhere!
if month <= 2:
year = year-1
month = month+12
a = int(year/100)
b = 2 - a + int(a * 0.25)
frac_of_day = (microsecond + (second + minute * 60 + hour * 3600)
) * 1.0 / (3600*24)
d = day + frac_of_day
jd = (int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + d +
b - 1524.5)
return jd
示例4: float_to_datestring
# 需要導入模塊: import time [as 別名]
# 或者: from time import month [as 別名]
def float_to_datestring(time):
"""Convert a floating point date to a date string
>>> float_to_datestring(2010.75)
'2010-10-01'
>>> float_to_datestring(2011.25)
'2011-04-01'
>>> float_to_datestring(2011.0)
'2011-01-01'
>>> float_to_datestring(2011.0 + 11.0 / 12)
'2011-12-01'
In some cases, the given float value can be truncated leading to unexpected
conversion between floating point and integer values. This function should
account for these errors by rounding months to the nearest integer.
>>> float_to_datestring(2011.9166666666665)
'2011-12-01'
>>> float_to_datestring(2016.9609856262834)
'2016-12-01'
"""
year = int(time)
# After accounting for the current year, extract the remainder and convert
# it to a month using the inverse of the logic used to create the floating
# point date. If the float date is sufficiently close to the end of the
# year, rounding can produce a 13th month.
month = min(int(np.rint(((time - year) * 12) + 1)), 12)
# Floating point dates do not encode day information, so we always assume
# they refer to the start of a given month.
day = 1
return "%s-%02d-%02d" % (year, month, day)
示例5: get_time_string
# 需要導入模塊: import time [as 別名]
# 或者: from time import month [as 別名]
def get_time_string():
'''
Returns current time in day_month_HH-MM-SS/ format
'''
time = datetime.now()
name = (str(time.day) + '_' + str(time.month) + '_%02d' % time.hour +
'-%02d' % time.minute + '-%02d' % time.second + '/')
return name
示例6: test_date_to_floatyear
# 需要導入模塊: import time [as 別名]
# 或者: from time import month [as 別名]
def test_date_to_floatyear(self):
r = utils.date_to_floatyear(0, 1)
self.assertEqual(r, 0)
r = utils.date_to_floatyear(1, 1)
self.assertEqual(r, 1)
r = utils.date_to_floatyear([0, 1], [1, 1])
np.testing.assert_array_equal(r, [0, 1])
yr = utils.date_to_floatyear([1998, 1998], [6, 7])
y, m = utils.floatyear_to_date(yr)
np.testing.assert_array_equal(y, [1998, 1998])
np.testing.assert_array_equal(m, [6, 7])
yr = utils.date_to_floatyear([1998, 1998], [2, 3])
y, m = utils.floatyear_to_date(yr)
np.testing.assert_array_equal(y, [1998, 1998])
np.testing.assert_array_equal(m, [2, 3])
time = pd.date_range('1/1/1800', periods=300*12-11, freq='MS')
yr = utils.date_to_floatyear(time.year, time.month)
y, m = utils.floatyear_to_date(yr)
np.testing.assert_array_equal(y, time.year)
np.testing.assert_array_equal(m, time.month)
myr = utils.monthly_timeseries(1800, 2099)
y, m = utils.floatyear_to_date(myr)
np.testing.assert_array_equal(y, time.year)
np.testing.assert_array_equal(m, time.month)
myr = utils.monthly_timeseries(1800, ny=300)
y, m = utils.floatyear_to_date(myr)
np.testing.assert_array_equal(y, time.year)
np.testing.assert_array_equal(m, time.month)
time = pd.period_range('0001-01', '6000-1', freq='M')
myr = utils.monthly_timeseries(1, 6000)
y, m = utils.floatyear_to_date(myr)
np.testing.assert_array_equal(y, time.year)
np.testing.assert_array_equal(m, time.month)
time = pd.period_range('0001-01', '6000-12', freq='M')
myr = utils.monthly_timeseries(1, 6000, include_last_year=True)
y, m = utils.floatyear_to_date(myr)
np.testing.assert_array_equal(y, time.year)
np.testing.assert_array_equal(m, time.month)
with self.assertRaises(ValueError):
utils.monthly_timeseries(1)
示例7: test_hydro_convertion
# 需要導入模塊: import time [as 別名]
# 或者: from time import month [as 別名]
def test_hydro_convertion(self):
# October
y, m = utils.hydrodate_to_calendardate(1, 1, start_month=10)
assert (y, m) == (0, 10)
y, m = utils.hydrodate_to_calendardate(1, 4, start_month=10)
assert (y, m) == (1, 1)
y, m = utils.hydrodate_to_calendardate(1, 12, start_month=10)
assert (y, m) == (1, 9)
y, m = utils.hydrodate_to_calendardate([1, 1, 1], [1, 4, 12],
start_month=10)
np.testing.assert_array_equal(y, [0, 1, 1])
np.testing.assert_array_equal(m, [10, 1, 9])
y, m = utils.calendardate_to_hydrodate(1, 1, start_month=10)
assert (y, m) == (1, 4)
y, m = utils.calendardate_to_hydrodate(1, 9, start_month=10)
assert (y, m) == (1, 12)
y, m = utils.calendardate_to_hydrodate(1, 10, start_month=10)
assert (y, m) == (2, 1)
y, m = utils.calendardate_to_hydrodate([1, 1, 1], [1, 9, 10],
start_month=10)
np.testing.assert_array_equal(y, [1, 1, 2])
np.testing.assert_array_equal(m, [4, 12, 1])
# Roundtrip
time = pd.period_range('0001-01', '1000-12', freq='M')
y, m = utils.calendardate_to_hydrodate(time.year, time.month,
start_month=10)
y, m = utils.hydrodate_to_calendardate(y, m, start_month=10)
np.testing.assert_array_equal(y, time.year)
np.testing.assert_array_equal(m, time.month)
# April
y, m = utils.hydrodate_to_calendardate(1, 1, start_month=4)
assert (y, m) == (0, 4)
y, m = utils.hydrodate_to_calendardate(1, 4, start_month=4)
assert (y, m) == (0, 7)
y, m = utils.hydrodate_to_calendardate(1, 9, start_month=4)
assert (y, m) == (0, 12)
y, m = utils.hydrodate_to_calendardate(1, 10, start_month=4)
assert (y, m) == (1, 1)
y, m = utils.hydrodate_to_calendardate(1, 12, start_month=4)
assert (y, m) == (1, 3)
y, m = utils.hydrodate_to_calendardate([1, 1, 1], [1, 4, 12],
start_month=4)
np.testing.assert_array_equal(y, [0, 0, 1])
np.testing.assert_array_equal(m, [4, 7, 3])
# Roundtrip
time = pd.period_range('0001-01', '1000-12', freq='M')
y, m = utils.calendardate_to_hydrodate(time.year, time.month,
start_month=4)
y, m = utils.hydrodate_to_calendardate(y, m, start_month=4)
np.testing.assert_array_equal(y, time.year)
np.testing.assert_array_equal(m, time.month)
示例8: get_c_e_data
# 需要導入模塊: import time [as 別名]
# 或者: from time import month [as 別名]
def get_c_e_data(chooseyear):
date_data = dict(year=[{"name":"一月", "cValue":0, "eValue":0}, {"name":"二月", "cValue":0, "eValue":0}, {"name":"三月", "cValue":0, "eValue":0}, {"name":"四月", "cValue":0, "eValue":0}, {"name":"五月", "cValue":0, "eValue":0}, {"name":"六月", "cValue":0, "eValue":0}, {"name":"七月", "cValue":0, "eValue":0}, {"name":"八月", "cValue":0, "eValue":0}, {"name":"九月", "cValue":0, "eValue":0}, {"name":"十月", "cValue":0, "eValue":0}, {"name":"十一月", "cValue":0, "eValue":0}, {"name":"十二月", "cValue":0, "eValue":0}], c_date=[], e_date=[])
standard_year = 2003
for year in range(standard_year, chooseyear+1):
date_data['c_date'].append({"name": year,"value":0})
date_data['e_date'].append({"name": year, "value": 0})
data = whois.select(whois.creation_date).where(whois.creation_date != '')
for date in data:
try:
try:
time = arrow.get(date.creation_date, 'DD-MMM-YYYY')
date_data['c_date'][time.year-standard_year]['value'] += 1
if time.year == chooseyear:
date_data['year'][time.month-1]["cValue"] += 1
except:
time = arrow.get(date.creation_date)
date_data['c_date'][time.year - standard_year]['value'] += 1
if time.year == chooseyear:
date_data['year'][time.month - 1]["cValue"] += 1
except:
pass
data1 = whois.select(whois.expiration_date).where(whois.expiration_date != '')
for date in data1:
try:
try:
time = arrow.get(date.expiration_date, 'DD-MMM-YYYY')
date_data['e_date'][time.year - standard_year]['value'] += 1
if time.year == chooseyear:
date_data['year'][time.month - 1]["eValue"] += 1
except:
time = arrow.get(date.expiration_date)
date_data['e_date'][time.year - standard_year]['value'] += 1
if time.year == chooseyear:
date_data['year'][time.month - 1]["eValue"] += 1
except:
pass
return json.dumps(date_data, ensure_ascii=False)
# 4.2惡意域名總體生存時間分布展示 橫軸動態定