rictirse 發表於 2012-12-15 14:28

Discuz! 時間計算產生器



產生日期由 1970/01/01-00:00:00 到您設置的時間經過幾秒

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

GUICreate ( "Discuz! Time Generator", 285, 90, Default, Default, 1)
GUISetOnEvent ( $GUI_EVENT_CLOSE, "SpecialEvents")

$iYear = GUICtrlCreateInput ( @YEAR, 10, 10, 60, 20, $ES_CENTER)
      GUICtrlCreateUpdown (-1)
$iMonth = GUICtrlCreateInput ( @MON, 70, 10, 40, 20, $ES_CENTER)
      GUICtrlCreateUpdown (-1)
$iDay = GUICtrlCreateInput ( @MDAY, 110, 10, 40, 20, $ES_CENTER)
      GUICtrlCreateUpdown (-1)
$iHour = GUICtrlCreateInput ( @HOUR, 150, 10, 40, 20, $ES_CENTER)
      GUICtrlCreateUpdown (-1)
$iMinute = GUICtrlCreateInput ( @MIN, 190, 10, 40, 20, $ES_CENTER)
      GUICtrlCreateUpdown (-1)
$iSecond = GUICtrlCreateInput ( @SEC, 230, 10, 40, 20, $ES_CENTER)
      GUICtrlCreateUpdown (-1)

$Btn = GUICtrlCreateButton ( "Generator", 100, 35, 80, 20)
      GUICtrlSetOnEvent( $Btn, "SpecialEvents")
GUISetState()

While True
      Sleep (50)
WEnd

Func SpecialEvents()
      Local $nTime
      Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Btn
                        $nTime = Cal_SecFrom1970Fix8( GUICtrlRead ($iYear), GUICtrlRead ($iMonth), GUICtrlRead ($iDay), GUICtrlRead ($iHour), GUICtrlRead ($iMinute), GUICtrlRead ($iSecond))
                        ToolTip ($nTime)
                        ClipPut ($nTime)
                        Sleep (500)
                        ToolTip ("")
      EndSwitch
EndFunc
Func IsLeapYear($Year)
      if Mod($Year, 400)==0 Then      return 1
      if Mod($Year, 100)==0 Then      return 0
      if Mod($Year, 4)==0      Then      return 1
      return 0
EndFunc

Func leap_year_cnt($year_beg, $year_end)
      Local $c1 = Int($year_beg/4)- Int($year_beg/100) + Int($year_beg/400)
      Local $c2 = Int($year_end/4)- Int($year_end/100) + Int($year_end/400)
      Return $c2-$c1 + IsLeapYear($year_beg) ;

EndFunc

Func Cal_NDays($year, $month, $day)
      Dim $Result = 0
      Dim $Days = [ 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
      $leap = IsLeapYear($year)

         $Result = $Days[$month] + $day
      If ($leap AND $month>2) Thenreturn ($Result+1)
      return $Result
EndFunc


Func Cal_SecFrom1970($year, $month, $day, $hour, $min, $sec)

      Local $year2         = $year-1
      Local $nLeapYear = leap_year_cnt(1970, $year2)
      Local $nNorYear   = ($year2 - 1970+ 1 )- $nLeapYear

      Local $year365_sec   = 31536000
      Local $year366_sec   = 31622400
      Local $days_sec            = 86400
      Local $hour_sec            = 3600
      Local $min_sec             = 60


      Local $ndays = Cal_NDays($year, $month, $day)-1
      Local $s1 =$nLeapYear * $year366_sec + $nNorYear * $year365_sec
      Local $s2 = $ndays * $days_sec
      Local $s3 = $hour * $hour_sec
      Local $s4 = $min * $min_sec

      return $s1 + $s2 + $s3 + $s4 + $sec

EndFunc

Func Cal_SecFrom1970Fix8($year, $month, $day, $hour, $min, $sec)

      Local $year2         = $year-1
      Local $nLeapYear = leap_year_cnt(1970, $year2)
      Local $nNorYear   = ($year2 - 1970+ 1 )- $nLeapYear

      Local $year365_sec   = 31536000
      Local $year366_sec   = 31622400
      Local $days_sec            = 86400
      Local $hour_sec            = 3600
      Local $min_sec             = 60
      
      Local $ndays = Cal_NDays($year, $month, $day)-1
      Local $s1 =$nLeapYear * $year366_sec + $nNorYear * $year365_sec
      Local $s2 = $ndays * $days_sec
      Local $s3 = $hour * $hour_sec
      Local $s4 = $min * $min_sec

      return $s1 + $s2 + $s3 + $s4 + $sec - 8*$hour_sec

EndFunc

teslaliu 發表於 2012-12-15 20:47

這個可以說明一下用途在哪嗎?
有點不是很清楚~感謝~

rictirse 發表於 2012-12-15 20:52

從SQL內修改發文日期、註冊日期在dz內有關於時間的都是這樣計算的。

esofthard 發表於 2012-12-15 22:56

teslaliu 發表於 2012-12-15 20:47 static/image/common/back.gif
這個可以說明一下用途在哪嗎?
有點不是很清楚~感謝~

簡單來說就是一個類似換算的東西啦

xx910203 發表於 2012-12-15 23:02

頁: [1]
查看完整版本: Discuz! 時間計算產生器