python2.7 the date of the operation

# - * - Coding: UTF-8 - * - 
Import Time
from datetime Import datetime
from datetime Import timedelta


DEF GET_TIME (time_type, delta_days):
"" "
get active time, according to type, delta_days to return time
: param of the type:
: param delta_days:
: return:
"" "
cur_date The time.strftime = ( 'M-%%% Y-D', time.localtime ()) # Get the current time

cur_date_time = datetime.strptime (cur_date, '% Y-% m- D% ')
"" "date and time of the user input string, to the processing date and time, must first be converted to str datetime.
conversion method is () is achieved by datetime.strptime, requires a formatted date and time string
after successful treatment to date for addition and subtraction. "" "
start_time = cur_date_time + timedelta(days=1)

end_time = cur_date_time + timedelta(days=delta_days)
"""timedelta对日期进行加减"""

== time_type. 1 IF:
START_DATE = start_time.strftime ( '% Y-M-% D% 00:00:00')
END_DATE = end_time.strftime ( '% Y-M-% D% 23:59:59')
the else:
START_DATE = start_time.strftime ( 'M-%%% Y-D')
END_DATE = end_time.strftime ( 'M-%%% Y-D')
active_time START_DATE = + '~' + END_DATE
Print ( 'active_time: {} 'the format (active_time)).

__main__' IF the __name__ == ':
GET_TIME (time_type = 2, delta_days = 2)


doing the interface automation, need to pass parameters, and in order to ensure that our use cases may be run repeatedly, the way time by each change to the parameter,

for example:
In Email Print The time.strftime = ( "test%H%M%[email protected]", time.localtime ()) # acquisition time parameters to achieve different transmission parameters.

The second way is to use third-party modules python faker (direct pip install faker on the line)

from faker import Faker
= Faker Fake ( "zh_CN") 

Print fake.email () so it can print out a different email


, or print testdata.get_email (name = 'dfd' ) so that you can print out at the beginning of the email dfd


 


Guess you like

Origin www.cnblogs.com/testling/p/12087992.html