How to make use of python timestamp conversion tool Detailed

This article is mainly to introduce the relevant information on how to make use of python timestamp conversion tools, sample code by text describes in great detail, has a certain reference value of learning for all of us to learn or work, you need the following with friends Xiao Bian to learn learn it together
preface:

Defined timestamp

Unix timestamp (Unix timestamp) or called Unix time (Unix time), POSIX time (POSIX time), is a time representation, defined from GMT January 1, 1970 00 hours 00 minutes 00 seconds until now the total number of seconds .Unix time stamp not only be used on Unix systems, Unix-like systems, but also many other operating systems are widely used. Most Unix systems will timestamp to save a 32-bit integer, which may cause some problems (Y2038 issue) in January 19, 2038.

Under normal circumstances, as a programmer, json and timestamps are two commonly used tools, I consulted a lot of friends, they are generally json format of online tools, or query timestamp. This is my way before use, deficiencies in this manner for the following:
1. Every time you open the cumbersome process steps, even if the collection also first open the browser, then click
2. If you open the browser tabs enough of them, could not find (that is to say of people like me)
3, etc.
then I found this tool after hijson locally formatted json, has been looking to find a local timestamp gadget. But since the largest Internet gods did not meet my needs. So I decided to write one.

Environment article

3.6 Python
Time Library
tkinter library
Optional: You can use pyinstaller packaged into exe file to run. Program size is about 8m, runtime memory footprint of about 15m.

First posted the code (because time is limited, do not write too neat, forgive me):

from tkinter import *
from time import *
 
'''
1、这个程序实现时间戳和日期格式的相互转换。
2、使用grid方法按照表格方式对组件位置进行安排
3、通过Button按钮进行转换和刷新操作。
4、通过Entry来获取用户输入。
'''
root = Tk()
root.title('时间戳转换')
root.resizable(0,0)#禁止拉伸 会变丑
# 对变量进行创建,和数据初始化
Label1 = Label(root, text='时间戳:').grid(row=0, column=0)
Label2 = Label(root, text='日期:').grid(row=1, column=0)
v1 = StringVar()
p1 = StringVar()
v1.set(int(time()))
 
Label3 = Label(root, text='日期:').grid(row=3, column=0)
Label4 = Label(root, text='时间戳').grid(row=4, column=0)
v2 = StringVar()
p2 = StringVar()
timeArray1 = localtime(int(time()))
v2.set(strftime("%Y-%m-%d %H:%M:%S", timeArray1))
p2.set(int(time()))
#时间戳转换成日期
def trans1():
 
 e1 = Entry(root, textvariable=v1) # Entry 是 Tkinter 用来接收字符串等输入的控件.
 e2 = Entry(root, textvariable=p1)
 e1.grid(row=0, column=1, padx=10, pady=5) # 设置输入框显示的位置,以及长和宽属性
 e2.grid(row=1, column=1, padx=10, pady=5)
 
 timeArray = localtime(int(e1.get()))
 p1.set(strftime("%Y-%m-%d %H:%M:%S", timeArray))
#日期转换为时间戳
def trans2():
 e3 = Entry(root, textvariable=v2) # Entry 是 Tkinter 用来接收字符串等输入的控件.
 e4 = Entry(root, textvariable=p2)
 e3.grid(row=3, column=1, padx=10, pady=5) # 设置输入框显示的位置,以及长和宽属性
 e4.grid(row=4, column=1, padx=10, pady=5)
 p2.set(int(mktime(strptime(e3.get(), "%Y-%m-%d %H:%M:%S"))))
#刷新第二个模组
def refresh():
 timeArray1 = localtime(int(time()))
 v2.set(strftime("%Y-%m-%d %H:%M:%S", timeArray1))
 p2.set(int(time()))
 
 
 
Button(root, text='转换', width=10, command=trans1) \
 .grid(row=2, column=0, sticky=W, padx=10, pady=5)
Button(root, text='转换', width=10, command=trans2) \
 .grid(row=5, column=0, sticky=W, padx=10, pady=5)
Button(root, text='刷新', width=10, command=refresh) \
 .grid(row=5, column=1, sticky=W, padx=10, pady=5)
Button(root, text='退出', width=10, command=root.quit) \
 .grid(row=6, column=1, sticky=E, padx=10, pady=5)
trans1()
trans2()
#设置窗口初始显示位置
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
x = (sw) / 2
y = (sh) / 2
root.geometry("+%d+%d" %(x,y))
mainloop()

I have always believed in the code written in too much good enough that no additional explanation. See comments in the code above

pyinstaller installation and use

installation

pip install pyinsatller
 
  
#安装直接运行一下如下命令
pyinstaller
#如果能运行会提示选项

Packed file

#打包的命令(在命令行中运行,如果不成功记得配置好环境变量)
pyinsatller -F -w D:\python\timeTran.py 
#选项介绍
#-F –onefile 产生一个文件用于部署 (参见XXXXX).
#-w,–windowed,–noconsole 使用Windows子系统执行.当程序启动的时候不会打开命令行(只对Windows有效) 就是不会显示一个黑窗口(太丑了,还要手动去关闭)如果不知道什么意思,可以自己去试试

github address: https: //github.com/VinterHe/timeTransverter (local download) which has packaged exe files can directly take to use
the build succeeds there will be a prompt INFO: Appending archive to EXE C: \ Users \ XXX \ dist \ timeTransverter.exe, which placed the exe file you want. Welcome to reprint and use, thank you.
We recommend the python learning sites , to see how old the program is to learn! From basic python script, reptiles, django, data mining, programming techniques, work experience, as well as senior careful study of small python partners to combat finishing zero-based information projects! Every day, Python programmers explain the timing of technology, to share some of the ways to learn and need to pay attention to small details.
Here Insert Picture Description

Published 21 original articles · won praise 9 · views 20000 +

Guess you like

Origin blog.csdn.net/haoxun06/article/details/104435743