Jump to content

Current Time?


Recommended Posts

$time = @Hour & ":" & @Min & ":" & @Sec

MsgBox(0,"Example", $time)

P.S. Also look up _Now() which should be a user-defined function in the latest stable version of AutoIt.

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

shit i got it... man i needed to add a shit load of crap.

Func _DateMonthOfYear($iMonthNum, $iShort)
;==============================================
; Local Constant/Variable Declaration Section
;==============================================
    Local $aMonthOfYear[13]
    
    $aMonthOfYear[1] = "January"
    $aMonthOfYear[2] = "February"
    $aMonthOfYear[3] = "March"
    $aMonthOfYear[4] = "April"
    $aMonthOfYear[5] = "May"
    $aMonthOfYear[6] = "June"
    $aMonthOfYear[7] = "July"
    $aMonthOfYear[8] = "August"
    $aMonthOfYear[9] = "September"
    $aMonthOfYear[10] = "October"
    $aMonthOfYear[11] = "November"
    $aMonthOfYear[12] = "December"
    
    Select
        Case Not StringIsInt($iMonthNum) Or Not StringIsInt($iShort)
            SetError(1)
            Return ""
        Case $iMonthNum < 1 Or $iMonthNum > 12
            SetError(1)
            Return ""
        Case Else
            Select
                Case $iShort = 0
                    Return $aMonthOfYear[$iMonthNum]
                Case $iShort = 1
                    Return StringLeft($aMonthOfYear[$iMonthNum], 3)
                Case Else
                    SetError(1)
                    Return ""
            EndSelect
    EndSelect
EndFunc  ;==>_DateMonthOfYear
Func _DateDayOfWeek($iDayNum, $iShort = 0)
;==============================================
; Local Constant/Variable Declaration Section
;==============================================
    Local $aDayOfWeek[8]
    
    $aDayOfWeek[1] = "Sunday"
    $aDayOfWeek[2] = "Monday"
    $aDayOfWeek[3] = "Tuesday"
    $aDayOfWeek[4] = "Wednesday"
    $aDayOfWeek[5] = "Thursday"
    $aDayOfWeek[6] = "Friday"
    $aDayOfWeek[7] = "Saturday"
    Select
        Case Not StringIsInt($iDayNum) Or Not StringIsInt($iShort)
            SetError(1)
            Return ""
        Case $iDayNum < 1 Or $iDayNum > 7
            SetError(1)
            Return ""
        Case Else
            Select
                Case $iShort = 0
                    Return $aDayOfWeek[$iDayNum]
                Case $iShort = 1
                    Return StringLeft($aDayOfWeek[$iDayNum], 3)
                Case Else
                    SetError(1)
                    Return ""
            EndSelect
    EndSelect
EndFunc  ;==>_DateDayOfWeek
Func _DateToDayOfWeek($iYear, $iMonth, $iDay)
    Local $i_aFactor
    Local $i_yFactor
    Local $i_mFactor
    Local $i_dFactor
; Verify If InputDate is valid
    If Not _DateIsValid($iYear & "/" & $iMonth & "/" & $iDay) Then
        SetError(1)
        Return ("")
    EndIf
    $i_aFactor = Int((14 - $iMonth) / 12)
    $i_yFactor = $iYear - $i_aFactor
    $i_mFactor = $iMonth + (12 * $i_aFactor) - 2
    $i_dFactor = Mod($iDay + $i_yFactor + Int($i_yFactor / 4) - Int($i_yFactor / 100) + Int($i_yFactor / 400) + Int((31 * $i_mFactor) / 12), 7)
    return ($i_dFactor + 1)
EndFunc  ;==>_DateToDayOfWeek
Func _DateIsLeapYear($iYear)
    If StringIsInt($iYear) Then
        Select
            Case Mod($iYear, 4) = 0 And Mod($iYear, 100) <> 0
                Return 1
            Case Mod($iYear, 400) = 0
                Return 1
            Case Else
                Return 0
        EndSelect
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc  ;==>_DateIsLeapYear
Func _DateTimeSplit($sDate, ByRef $asDatePart, ByRef $iTimePart)
    Local $sDateTime
    Local $x
; split the Date and Time portion
    $sDateTime = StringSplit($sDate, " T")
; split the date portion
    If $sDateTime[0] > 0 Then $asDatePart = StringSplit($sDateTime[1], "/-.")
; split the Time portion
    If $sDateTime[0] > 1 Then
        $iTimePart = StringSplit($sDateTime[2], ":")
        If UBound($iTimePart) < 4 Then ReDim $iTimePart[4]
    Else
        Dim $iTimePart[4]
    EndIf
; Ensure the arrays contain 4 values
    If UBound($asDatePart) < 4 Then ReDim $asDatePart[4]
; update the array to contain numbers not strings
    For $x = 1 To 3
        $asDatePart[$x] = Number($asDatePart[$x])
        $iTimePart[$x] = Number($iTimePart[$x])
    Next
    Return (1)
EndFunc  ;==>_DateTimeSplit
Func _DateIsValid($sDate)
    Local $asDatePart[4]
    Local $asTimePart[4]
    Local $iNumDays
    $iNumDays = "31,28,31,30,31,30,31,31,30,31,30,31"
    $iNumDays = StringSplit($iNumDays, ",")
; split the date and time into arrays
    _DateTimeSplit($sDate, $asDatePart, $asTimePart)
    If $asDatePart[0] <> 3 Then
        Return (0)
    EndIf
; verify valid input date values
    If _DateIsLeapYear($asDatePart[1]) Then $iNumDays[2] = 29
    If $asDatePart[1] < 1900 Or $asDatePart[1] > 2999 Then Return (0)
    If $asDatePart[2] < 1 Or $asDatePart[2] > 12 Then Return (0)
    If $asDatePart[3] < 1 Or $asDatePart[3] > $iNumDays[$asDatePart[2]] Then Return (0)
    
; verify valid input Time values
    If $asTimePart[0] < 1 Then Return (1)   ; No time specified so date must be correct
    If $asTimePart[0] < 2 Then Return (0)   ; need at least HH:MM when something is specified
    If $asTimePart[1] < 0 Or $asTimePart[1] > 23 Then Return (0)
    If $asTimePart[2] < 0 Or $asTimePart[2] > 59 Then Return (0)
    If $asTimePart[3] < 0 Or $asTimePart[3] > 59 Then Return (0)
; we got here so date/time must be good
    Return (1)
EndFunc  ;==>_DateIsValid
Func _DateTimeFormat($sDate, $sType)
    Local $asDatePart[4]
    Local $asTimePart[4]
    Local $sReg_DateValue = ""
    Local $sReg_TimeValue = ""
    Local $sTempDate
    Local $sNewTime
    Local $sNewDate
    Local $sAM
    Local $sPM
    Local $iWday
; Verify If InputDate is valid
    If Not _DateIsValid($sDate) Then
        SetError(1)
        Return ("")
    EndIf
; input validation
    If $sType < 0 Or $sType > 5 Or Not IsInt($sType) Then
        SetError(2)
        Return ("")
    EndIf
; split the date and time into arrays
    _DateTimeSplit($sDate, $asDatePart, $asTimePart)
    
    If $sType = 0 Then
        $sReg_DateValue = "sShortDate"
        If $asTimePart[0] > 1 Then $sReg_TimeValue = "sTimeFormat"
    EndIf
    
    If $sType = 1 Then $sReg_DateValue = "sLongDate"
    If $sType = 2 Then $sReg_DateValue = "sShortDate"
    If $sType = 3 Then $sReg_TimeValue = "sTimeFormat"
    If $sType = 4 Then $sReg_TimeValue = "sTime"
    If $sType = 5 Then $sReg_TimeValue = "sTime"   ; 24 hour clock
    $sNewDate = ""
    If $sReg_DateValue <> "" Then
        $sTempDate = RegRead("HKEY_CURRENT_USER\Control Panel\International", $sReg_DateValue)
        $sAM = RegRead("HKEY_CURRENT_USER\Control Panel\International", "s1159")
        $sPM = RegRead("HKEY_CURRENT_USER\Control Panel\International", "s2359")
        If $sAM = "" Then $sAM = "AM"
        If $sPM = "" Then $sPM = "PM"
        $iWday = _DateToDayOfWeek($asDatePart[1], $asDatePart[2], $asDatePart[3])
        $asDatePart[3] = StringRight("0" & $asDatePart[3], 2); make sure the length is 2
        $asDatePart[2] = StringRight("0" & $asDatePart[2], 2); make sure the length is 2
        $sTempDate = StringReplace($sTempDate, "d", "@")
        $sTempDate = StringReplace($sTempDate, "m", "#")
        $sTempDate = StringReplace($sTempDate, "y", "&")
        $sTempDate = StringReplace($sTempDate, "@@@@", _DateDayOfWeek($iWday, 0))
        $sTempDate = StringReplace($sTempDate, "@@@", _DateDayOfWeek($iWday, 1))
        $sTempDate = StringReplace($sTempDate, "@@", $asDatePart[3])
        $sTempDate = StringReplace($sTempDate, "@", StringReplace(StringLeft($asDatePart[3], 1), "0", "") & StringRight($asDatePart[3], 1))
        $sTempDate = StringReplace($sTempDate, "####", _DateMonthOfYear($asDatePart[2], 0))
        $sTempDate = StringReplace($sTempDate, "###", _DateMonthOfYear($asDatePart[2], 1))
        $sTempDate = StringReplace($sTempDate, "##", $asDatePart[2])
        $sTempDate = StringReplace($sTempDate, "#", StringReplace(StringLeft($asDatePart[2], 1), "0", "") & StringRight($asDatePart[2], 1))
        $sTempDate = StringReplace($sTempDate, "&&&&", $asDatePart[1])
        $sTempDate = StringReplace($sTempDate, "&&", StringRight($asDatePart[1], 2))
        $sNewDate = $sTempDate
    EndIf
    If $sReg_TimeValue <> "" Then
        $sNewTime = RegRead("HKEY_CURRENT_USER\Control Panel\International", $sReg_TimeValue)
        If $sType = 4 Then
            $sNewTime = StringFormat( "%02d", $asTimePart[1]) & $sNewTime & StringFormat( "%02d", $asTimePart[2])
        ElseIf $sType = 5 Then
            $sNewTime = StringFormat( "%02d", $asTimePart[1]) & $sNewTime & StringFormat( "%02d", $asTimePart[2]) & $sNewTime & StringFormat( "%02d", $asTimePart[3])
        Else
            If $sType <> 0 Then
                If $asTimePart[1] < 12 Then
                    $sNewTime = StringReplace($sNewTime, "tt", "AM")
                    If $asTimePart[1] = 0 Then $asTimePart[1] = 12
                Else
                    $sNewTime = StringReplace($sNewTime, "tt", "PM")
                    If $asTimePart[1] > 12 Then $asTimePart[1] = $asTimePart[1] - 12
                EndIf
            EndIf
            $asTimePart[1] = StringRight("0" & $asTimePart[1], 2); make sure the length is 2
            $asTimePart[2] = StringRight("0" & $asTimePart[2], 2); make sure the length is 2
            $asTimePart[3] = StringRight("0" & $asTimePart[3], 2); make sure the length is 2
            $sNewTime = StringReplace($sNewTime, "hh", StringFormat( "%02d", $asTimePart[1]))
            $sNewTime = StringReplace($sNewTime, "h", StringReplace(StringLeft($asTimePart[1], 1), "0", "") & StringRight($asTimePart[1], 1))
            $sNewTime = StringReplace($sNewTime, "mm", StringFormat( "%02d", $asTimePart[2]))
            $sNewTime = StringReplace($sNewTime, "ss", StringFormat( "%02d", $asTimePart[3]))
        EndIf
        $sNewDate = StringStripWS($sNewDate & " " & $sNewTime, 3)
    EndIf
    Return ($sNewDate)
EndFunc  ;==>_DateTimeFormat
Func _NowTime($sType = 3)
    If $sType < 3 Or $sType > 5 Then $sType = 3
    Return (_DateTimeFormat(@YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC, $sType))
EndFunc  ;==>_NowTime
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...