风行者 发表于 2010-7-14 13:33:19

[已解决]时间转换

本帖最后由 风行者 于 2010-7-14 14:37 编辑

JavaScript---new Date().getTime()的方法,用au3怎样转换?

风行者 发表于 2010-7-14 14:36:24

问题已解决

zcx880517 发表于 2010-7-14 14:51:26

贴个时间转换器代码给你看下#include <GUIConstants.au3>

Global Const $SS_SUNKEN             = 0x1000
Global Const $WM_COMMAND = 0x0111
Global Const $UDS_ALIGNLEFT             = 0x0008
Global Const $ES_RIGHT = 2
Global Const $ES_LEFT = 0

;Create GUI
$AForm1 = GUICreate("Time Breakdown", 510, 150, 417, 181)

;Create The Group
$MainGrp = GUICtrlCreateGroup("时间转换器", 8, 8, 490, 113)

;Create Labels
$mmLabel = GUICtrlCreateLabel("毫秒", 24, 56, 75, 17)
$sLabel = GUICtrlCreateLabel("秒", 118, 56, 75, 17)
$mLabel = GUICtrlCreateLabel("分钟", 191, 56, 75, 17)
$hLabel = GUICtrlCreateLabel("小时", 278, 56, 75, 17)
$hLabel = GUICtrlCreateLabel("天", 362, 56, 75, 17)
$hLabel = GUICtrlCreateLabel("星期", 438, 56, 55, 17)

;Create inputs
$mm = GUICtrlCreateInput("", 16, 32, 73, 21, $ES_LEFT)
$s = GUICtrlCreateInput("", 97, 32, 73, 21, $ES_LEFT)
$m = GUICtrlCreateInput("", 176, 32, 73, 21, $ES_LEFT)
$h = GUICtrlCreateInput("", 255, 32, 73, 21, $ES_LEFT)
$d = GUICtrlCreateInput("", 336, 32, 73, 21, $ES_LEFT)
$w = GUICtrlCreateInput("", 417, 32, 73, 21, $ES_LEFT)

;Create buttons
$clear = GUICtrlCreateButton("清除", 88, 90, 105, 25)
$Exit = GUICtrlCreateButton("退出", 250, 90, 105, 25)

;Create status bar
$Status = GUICtrlCreateLabel("", 0, 133, 510, 17,$SS_SUNKEN)
GUISetState(@SW_SHOW)

;Conversion handler
GUIRegisterMsg($WM_COMMAND,"_TEST")
$i = 0
Func _TEST($hWnd, $Msg, $wParam, $lParam)
   Local $nNotifyCode   = BitShift($wParam, 16)
   Local $nID             = BitAnd($wParam, 0x0000FFFF)
   Local $hCtrl         = $lParam
   Local $EN_CHANGE = 0x0300
   If $nNotifyCode = $EN_CHANGE Then
   Switch $nID
         Case $mm
             MMConvert()
         Case $s
             SConvert()
         Case $m
             MConvert()
         Case $h
             HConvert()
         Case $d
             DConvert()
         Case $w
             WConvert()
   EndSwitch
   EndIf
   Return $GUI_RUNDEFMSG
EndFunc

;Creat loop
While 1
   $msg = GUIGetMsg()
   Select
         Case $msg = $GUI_Event_Close
             Exit 0
Case $msg = $clear
   GUICtrlSetData($mm,"")
   GUICtrlSetData($s,"")
   GUICtrlSetData($m,"")
   GUICtrlSetData($h,"")
   GUICtrlSetData($d,"")
   GUICtrlSetData($w,"")
Case $msg = $Exit
             Exit
   EndSelect
WEnd

Func MMConvert()   ;==>MMConvert
   $r = GUICtrlRead($mm)
If $r > 0 Then
   GUICtrlSetData($Status,"")

GUICtrlSetData($mm, Number($r))
GUICtrlSetData($s, Number($r/1000))
GUICtrlSetData($m, Number($r/60000))
GUICtrlSetData($h, Number($r/3600000))
GUICtrlSetData($d, Number($r/86400000   ))
GUICtrlSetData($w, Number($r/604800000))
Else
         GUICtrlSetData($Status,"Please input P Number")
EndIf

EndFunc   ;==>MMConvert

Func SConvert()   ;==>SConvert
   $r = GUICtrlRead($s)
If $r > 0 Then
GUICtrlSetData($Status,"")
GUICtrlSetData($mm, Number($r * 1000))
GUICtrlSetData($s, Number($r))
GUICtrlSetData($m, Number($r /60))
GUICtrlSetData($h, Number($r/3600))
GUICtrlSetData($d, Number($r/86400))
GUICtrlSetData($w, Number($r/604800))
Else
         GUICtrlSetData($Status,"Please input S Number")
EndIf

EndFunc   ;==>SConvert

Func MConvert()   ;==>MConvert
   $r = GUICtrlRead($m)
If $r > 0 Then
GUICtrlSetData($Status,"")
GUICtrlSetData($mm, Number($r * 60000))
GUICtrlSetData($s, Number($r * 60))
GUICtrlSetData($m, Number($r))
GUICtrlSetData($h, Number($r/60))
GUICtrlSetData($d, Number($r/1440))
GUICtrlSetData($w, Number($r/10080))
Else
         GUICtrlSetData($Status,"Please input a digit")
EndIf

EndFunc   ;==>MConvert

Func HConvert()   ;==>HConvert
   $r = GUICtrlRead($h)
If $r > 0 Then
GUICtrlSetData($Status,"")
GUICtrlSetData($mm, Number($r * 3600000))
GUICtrlSetData($s, Number($r * 3600))
GUICtrlSetData($m, Number($r * 60))
GUICtrlSetData($h, Number($r))
GUICtrlSetData($d, Number($r/24))
GUICtrlSetData($w, Number($r/168))
Else
         GUICtrlSetData($Status,"Please input a digit")
EndIf

EndFunc   ;==>HConvert

Func DConvert()   ;==>DConvert
   $r = GUICtrlRead($d)
If $r > 0 Then
GUICtrlSetData($Status,"")
GUICtrlSetData($mm, Number($r * 86400000))
GUICtrlSetData($s, Number($r * 86400))
GUICtrlSetData($m, Number($r * 1440))
GUICtrlSetData($h, Number($r * 24))
GUICtrlSetData($d, Number($r))
GUICtrlSetData($w, Number($r/7))
Else
         GUICtrlSetData($Status,"Please input a digit")
EndIf

EndFunc   ;==>DConvert

Func WConvert()   ;==>WConvert
   $r = GUICtrlRead($w)
If $r > 0 Then
GUICtrlSetData($Status,"")
GUICtrlSetData($mm, Number($r * 604800000))
GUICtrlSetData($s, Number($r * 604800))
GUICtrlSetData($m, Number($r * 10080))
GUICtrlSetData($h, Number($r * 168   ))
GUICtrlSetData($d, Number($r * 7))
GUICtrlSetData($w, Number($r))
Else
         GUICtrlSetData($Status,"Please input a digit")
EndIf

EndFunc   ;==>WConvert

shypro2009 发表于 2010-7-14 20:29:54

JavaScript: date.getTime():
定义和用法
该getTime()方法返回自1970年1月1日午夜的毫秒,和指定日数。
注:此方法是始终与一个日期对象一起使用。

3mile 发表于 2010-7-14 20:36:14

date ( )对应:#include <Date.au3>
MsgBox(0,'',"The Date is:" & _NowDate())getTime ( )对应:$iDateCalc = _DateDiff( 's',"1970/01/01 00:00:00",_NowCalc())
MsgBox( 4096, "", "Number of seconds since EPOCH: " & $iDateCalc )#Include <Date.au3>
_DateDiff($sType, $sStartDate, $sEndDate)

$sType下列之一:
d - 给定日期间天的不同
m - 给定日期间月的不同
y - 给定日期间年的不同
w - 给定日期间周的不同
h - 给定日期间小时的不同
n - 给定日期间分钟的不同
s - 给定日期间秒的不同
$sStartDate
输入"YYYY/MM/DD[ HH:MM:SS]"格式的开始日期
$sEndDate
输入"YYYY/MM/DD[ HH:MM:SS]"格式的结尾日期

风行者 发表于 2010-7-15 00:30:10

本帖最后由 风行者 于 2010-7-15 00:34 编辑

谢谢3mile,帮助的例子没看到,不过跟js返回的结果少了几位数,数字也有点不同
我用au3调用js代码能实现了
页: [1]
查看完整版本: [已解决]时间转换