When automated, time-stamp processing

# - * - Coding: UTF-. 8 - * - 

from Setting Import *
Import datetime

sys.path.append (LIB_DIR)
# Print (LIB_DIR)


class TimeFormat:
'' 'time format' ''

DEF now_time (Self, the format) :
'' '
current time
: param format: timestamp format
: return: return to the current time
' ''
the try:
return datetime.datetime.now () the strftime (the format).
the except Exception AS E:
return E

DEF n_days_later (Self, n- , the format):
'' '
n days time
: days: param n
: param the format: timestamp format
: return: return time n days
' ''
try:
. Time = (datetime.datetime.now () + the datetime.timedelta (Days = n)) the strftime (the format)
return Time
the except Exception AS E:
return E


: DEF n_hours_later (Self, n, the format)
'' '
after n hours time
: hours: n-param
: param the format:
: return:
'' '
the try:
. time = (datetime.datetime.now () + the datetime.timedelta (= n-hours)) the strftime (the format)
return time
the except Exception AS E:
return E

DEF n_minutes_later (Self, n, the format):
'' '
after n minutes
: param n: min
: param format:
:return:
'''
try:
time = (datetime.datetime.now() + datetime.timedelta(minutes=n)).strftime(format)
return time
except Exception as e:
return e



if __name__ == '__main__':
t = TimeFormat()
s = t.now_time("%Y-%m-%d %H:%M:%S")
l = t.n_hours_later(n=100, format="%Y-%m-%d %H:%M:%S")
print(s)
print(l)

Guess you like

Origin www.cnblogs.com/jinbaobao/p/11988335.html