Python timestamp to date date to timestamp
The environment of this articleIn general, as a programmer, JSON and timestamps are commonly used two tools, I consulted many friends, they are generally through the online tool to format JSON, or query timestamp. This is also the way I used it before, and the disadvantages of this approach are as follows:
1. Each time you open the process is tedious, even if you have to open the browser, and then click
2. If you open a browser with enough tags, you can't find it (that is, someone like me)
3. etc.
And then I found out Hijson. After the tool can format the JSON locally, it has been looking for a small tool to find the timestamp locally. Alas, the Internet gods did not meet my needs. So I decided to write one myself.
Optional: You can use the Pyinstaller package to run as an EXE file. The program size is approximately 8m, and the run-time memory consumes about 15m.
First paste the code (because the time is limited, not written too neat, forgive me):
From Tkinter Import *from time import * ' 1, this program enables the conversion of timestamps and date formats to each other. 2. Use the Grid method to arrange the location of the components in tabular Format 3, through the button buttons to transform and refresh operations. 4, through the entry to obtain user input. "root = Tk () root.title (' timestamp conversion ') root.resizable (0,0) #禁止拉伸 Ugly # Create a variable, and initialize the data Label1 = Label (root, text= ' timestamp: '). Grid ( Row=0, column=0) Label2 = Label (root, text= ' Date: '). Grid (Row=1, column=0) v1 = stringvar () p1 = Stringvar () v1.set (int (Time () ) Label3 = label (root, text= ' Date: '). Grid (Row=3, column=0) Label4 = label (root, text= ' timestamp '). 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 is a control used by Tkinter to receive input such as strings. E2 = Entry (root, Textvariable=p1) E1.grid (row=0, Column=1, padx=10, pady=5) # Sets the position of the input box display, as well as the long and wide properties E2.grid (Row=1, col Umn=1, padx=10, pady=5) Timearray = localtime (int (e1.get ())) P1.set (Strftime ("%y-%m-%d%h:%m:%s", Timearray)) #日期转换为时 Inter-stamp Def trans2 (): E3 = Entry (Root, Textvariable=v2# Entry is a control that Tkinter uses to receive input such as strings. E4 = Entry (Root, Textvariable=p2) E3.grid (row=3, Column=1, padx=10, pady=5) # Sets the position of the input box display, as well as the long and wide properties E4.grid (row=4, col Umn=1, padx=10, pady=5) p2.set (int (mktime (Strptime (), "E3.get%y-%m-%d"))) #刷新第二个模组def Refresh ():%h:%m:%s 1 = localtime (int (time ())) V2.set (Strftime ("%y-%m-%d%h:%m:%s", TimeArray1)) p2.set (int (time ())) Button (root, text= ' go Change ', width=10, command=trans1) \. Grid (row=2, column=0, Sticky=w, padx=10, pady=5) Button (root, text= ' convert ', width=10, comm AND=TRANS2) \. Grid (Row=5, column=0, Sticky=w, padx=10, pady=5) Button (root, text= ' refresh ', width=10, Command=refresh) \ . Grid (Row=5, Column=1, Sticky=w, padx=10, pady=5) Button (Root, text= ' exit ', width=10, command=root.quit) \. Grid (Row=6, CO Lumn=1, Sticky=e, padx=10, pady=5) trans1 () trans2 () #设置窗口初始显示位置sw = Root.winfo_screenwidth () sh = root.winfo_ ScreenHeight () x = (sw)/2y = (SH)/2root.geometry ("+%d+%d"% (x, y)) Mainloop ()
I have always believed that the code was written well enough to require too many explanations. Take a look at the comments in the code above
Installation and use of PyinstallerPackaging filespip install pyinsatller#安装直接运行一下如下命令pyinstaller#如果能运行会提示选项
#打包的命令(在命令行中运行,如果不成功记得配置好环境变量)pyinsatller -F -w D:\python\timeTran.py #选项介绍#-F –onefile 产生一个文件用于部署 (参见XXXXX).#-w,–windowed,–noconsole 使用Windows子系统执行.当程序启动的时候不会打开命令行(只对Windows有效) 就是不会显示一个黑窗口(太丑了,还要手动去关闭)如果不知道什么意思,可以自己去试试
GitHub Address: Github.com/vinterhe/timetransverter inside there are packaged EXE files can be directly taken to use
After the successful generation, there will be a info:appending archive to exe C:\Users\XXX\dist\timeTransverter.exe, which contains the EXE file you want. Welcome everyone and use, thank you.