?im 使用此命令獲取請求的時間戳(紀元時間)。
我正在使用 bash 命令 date 并且它對我有用,但是使用這個 python cmd 我以另一種格式獲取日期。
猛擊
date %s%3N
bash 輸出
1640426436567
Python
import subprocess
start = subprocess.Popen(["date", " %s%3N"], stdout=subprocess.PIPE, shell=True).communicate()[0]
print(str(start))
蟒蛇輸出
b'Sat Dec 25 05:37:04 AM EST 2021\n
知道如何解決這個問題嗎?
uj5u.com熱心網友回復:
試試這個:
import subprocess
start1 = subprocess.Popen("date %s%3N", stdout=subprocess.PIPE, shell=True).communicate()[0]
start2 = subprocess.Popen(["date", ' %s%3N'], stdout=subprocess.PIPE).communicate()[0]
print("shell=True", start1)
print("shell=False", start2)
輸出
shell=True b'1640435179481\n'
shell=False b'1640435179488\n'
到字串 ->(解碼和剝離)
start1 = subprocess.Popen("date %s%3N", stdout=subprocess.PIPE, shell=True).communicate()[0].decode("utf-8").strip()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/393520.html
