-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
90 lines (78 loc) · 2.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"fmt"
"github.com/ying32/govcl/vcl"
"strconv"
"time"
_ "github.com/ying32/govcl/pkgs/winappres"
"github.com/ying32/govcl/vcl/types"
)
type TMainForm struct {
*vcl.TForm
Button1 *vcl.TButton
Text1 *vcl.TLabeledEdit
ConvertText *vcl.TLabeledEdit
}
type TForm1 struct {
*vcl.TForm
Button1 *vcl.TButton
}
var (
mainForm *TMainForm
form1 *TForm1
)
func main() {
vcl.DEBUG = true
vcl.RunApp(&mainForm, &form1)
}
func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
f.SetCaption("Timestamp Convert")
f.EnabledMaximize(false)
f.SetWidth(600)
f.SetHeight(600)
f.ScreenCenter()
f.Text1 = vcl.NewLabeledEdit(f)
f.Text1.SetParent(f)
f.Text1.SetLeft(250)
f.Text1.SetWidth(200)
f.Text1.SetTop(100)
f.Text1.SetLabelPosition(types.LpLeft)
f.Text1.SetLabelSpacing(6)
f.Text1.EditLabel().SetCaption("输入时间戳或时间:")
f.Button1 = vcl.NewButton(f)
f.Button1.SetParent(f)
f.Button1.SetCaption("转换为为时间戳或时间")
f.Button1.SetLeft(250)
f.Button1.SetWidth(200)
f.Button1.SetHeight(40)
f.Button1.SetTop(150)
f.Button1.SetOnClick(f.OnButton1Click)
f.Button1.Font().SetStyle(types.NewSet(types.FsBold)) //f.Button1.Font().Style().Include(types.FsBold))
f.ConvertText = vcl.NewLabeledEdit(f)
f.ConvertText.SetParent(f)
f.ConvertText.SetLeft(250)
f.ConvertText.SetWidth(200)
f.ConvertText.SetTop(200)
f.ConvertText.SetLabelPosition(types.LpLeft)
f.ConvertText.SetLabelSpacing(6)
f.ConvertText.EditLabel().SetCaption("结果:")
}
func (f *TMainForm) OnFormCloseQuery(Sender vcl.IObject, CanClose *bool) {
//*CanClose = vcl.MessageDlg("是否退出?", types.MtConfirmation, types.MbYes, types.MbNo) == types.IdYes
}
func (f *TMainForm) OnButton1Click(object vcl.IObject) {
var buf string
f.Text1.GetTextBuf(&buf, 25)
if buf == `` {
f.ConvertText.SetText(`输入结果为空`)
return
}
num, err := strconv.ParseInt(buf, 10, 64)
if err != nil {
t, _ := time.Parse("2006-01-02 15:04:05", buf)
f.ConvertText.SetText(fmt.Sprintf(`%v`, t.Unix()))
return
}
t := time.Unix(num, 0).Format("2006-01-02 15:04:05")
f.ConvertText.SetText(t)
}