2019-06-20

python 生成当前时间时间戳

int(time,time()*1000)

获取指定年月日时间戳

def get_end_time(x2, y2, z2):
    s = datetime.datetime(x2, y2, z2, 00, 00, 00)
    print(s)
    end_time = int(time.mktime(s.timetuple())) * 1000

python 连接数据库

db = pymysql.connect(
        host='cn-master.cgl0jlkt5nez.rds.cn-north-1.amazonaws.com.cn',
        user='jialin',
        password='jialin',
        db='stats',
        port=3306
                        )
#创建游标
coursor = db.cursor()
 # 需要执行的sql
sql = 'select * from t_record_start where rstart_appChannel="{0}" and rstart_type="1"' \
       ' and rstart_platform="2" and rstart_clientCreateDate between "{1}" and ' \
       '"{2}"'.format(i, start_time, end_time)
 # 执行游标     a 为查询到数据数量
 a = coursor.execute(sql)       
 # 打印出每一条查询结果
 for y in range(a):
     result = coursor.fetchone()
     print(result)
# 关闭连接   
db.close()

你可能感兴趣的:(2019-06-20)