学习时间转换的小例子,涉及文本转时间戳、时间戳转文本、双击、单击事件,复制到剪贴板、从剪贴板读取内容等知识点;
[AAuto] 纯文本查看 复制代码 import win.ui;
import fsys.time;
import win
import win.clip
/*DSG{{*/
mainForm = win.form(text="时间戳转换";right=757;bottom=467;max=false)
mainForm.add(
button={cls="button";text="时间戳转成文本";left=276;top=143;right=466;bottom=171;z=15};
button3={cls="button";text="文本转成时间戳";left=276;top=96;right=466;bottom=124;z=9};
button4={cls="button";text="清空";left=271;top=376;right=414;bottom=423;z=10};
current_stamp={cls="edit";left=102;top=54;right=264;bottom=82;edge=1;multiline=1;z=4};
current_stamp2={cls="edit";text="双击复制";left=578;top=96;right=740;bottom=124;edge=1;multiline=1;z=8};
current_stamp3={cls="edit";text="单击粘贴";left=104;top=144;right=266;bottom=172;edge=1;multiline=1;z=12};
current_time={cls="edit";left=102;top=15;right=264;bottom=43;edge=1;multiline=1;z=2};
current_time2={cls="edit";text="单击粘贴";left=103;top=96;right=265;bottom=124;edge=1;multiline=1;z=6};
current_time3={cls="edit";text="双击复制";left=578;top=144;right=740;bottom=172;edge=1;multiline=1;z=14};
static={cls="static";text="当前时间";left=16;top=14;right=91;bottom=42;center=1;transparent=1;z=1};
static2={cls="static";text="当前时间戳";left=17;top=53;right=92;bottom=81;center=1;transparent=1;z=3};
static3={cls="static";text="文本时间";left=16;top=96;right=91;bottom=124;center=1;transparent=1;z=5};
static4={cls="static";text="时间戳";left=492;top=96;right=567;bottom=124;center=1;transparent=1;z=7};
static5={cls="static";text="时间戳";left=16;top=143;right=91;bottom=171;center=1;transparent=1;z=11};
static6={cls="static";text="文本时间";left=492;top=143;right=567;bottom=171;center=1;transparent=1;z=13}
)
/*}}*/
mainForm.setInterval(
function() {
var now = time.now();
mainForm.current_time.text = time(now, "%Y-%m-%d %H:%M:%S");
//mainForm.current_stamp.text = tostring(tonumber(time(now)));
mainForm.current_stamp.text = time.stamp(true);
// 定时执行参数 @1 指定的回调函数,参数 @2 指定间隔毫秒数
}, 1000
);
//复制当前时间到剪贴板
mainForm.current_time.wndproc = function(hwnd, message, wParam, lParam) {
if (message == 0x203 /*_WM_LBUTTONDBLCLK*/ ) {
win.clip.write(mainForm.current_time.text);
return true;
}
}
//复制当前时间戳到剪贴板
mainForm.current_stamp.wndproc = function(hwnd, message, wParam, lParam) {
if (message == 0x203 /*_WM_LBUTTONDBLCLK*/ ) {
win.clip.write(mainForm.current_stamp.text);
return true;
}
}
//从剪贴板读取数据
mainForm.current_time2.oncommand = function(id, event) {
mainForm.current_time2.text = win.clip.read();
}
mainForm.button3.oncommand = function(id, event) {
var input = mainForm.current_time2.text
if (input == "") {
return;
}
if string.indexAny(input, "-")==null {
return;
}
mainForm.current_stamp2.text = tostring(tonumber(time(input)) * 1000);
}
msTime = function(ms) {
var tm = time(ms / 1000, "%Y-%m-%d %H:%M:%S");
return tm;
}
//从剪贴板读取数据
mainForm.current_stamp3.oncommand = function(id, event) {
mainForm.current_stamp3.text = win.clip.read();
}
mainForm.button.oncommand = function(id, event) {
var input = mainForm.current_stamp3.text
if (input == "") {
return;
}
if string.indexAny(input, "-")!=null {
return;
}
mainForm.current_time3.text = msTime(input);
}
//复制当前时间到剪贴板
mainForm.current_time3.wndproc = function(hwnd, message, wParam, lParam) {
if (message == 0x203 /*_WM_LBUTTONDBLCLK*/ ) {
win.clip.write(mainForm.current_time3.text);
return true;
}
}
//复制当前时间戳到剪贴板
mainForm.current_stamp2.wndproc = function(hwnd, message, wParam, lParam) {
if (message == 0x203 /*_WM_LBUTTONDBLCLK*/ ) {
win.clip.write(mainForm.current_stamp2.text);
return true;
}
}
mainForm.button4.oncommand = function(id, event) {
mainForm.current_time2.text = ""
mainForm.current_stamp2.text = ""
mainForm.current_time3.text = ""
mainForm.current_stamp3.text = ""
}
mainForm.show();
return win.loopMessage();
|