md5加密以及获取时间戳

导入的包

from urllib import parse,request
from flask import Flask
import hashlib
import pymysql
import json
import time

定义md5加密规则

def encrypt_md5(str=''):
    md = hashlib.md5()  # 创建md5对象
    md.update(str.encode(encoding='utf-8'))  # 这里必须用encode()函数对字符串进行编码,不然会报 TypeError: Unicode-objects must be encoded before hashing
    return md.hexdigest()  # 加密

password = encrypt_md5(password1)

获取时间戳(14位)

def time_now():
    now = int(round(time.time()*1000))
    now02 = time.strftime('%Y%m%d%H%M%S',time.localtime(now/1000))
    return now02

获取时间戳(10)位

dt = '2018-01-01 10:40:30'
ts = int(time.mktime(time.strptime(dt, "%Y-%m-%d %H:%M:%S")))
print (ts)

获取时间戳(13)位

millis = int(round(time.time() * 1000))

仅作笔记.

猜你喜欢

转载自blog.csdn.net/qq_42597385/article/details/86227244