Autohotkey:将值设置为DateTime

时间:2013-10-18 06:56:51

标签: autohotkey

有谁能告诉我如何将'01 / Jan / 1999'设置为DateTime?

我试过这个,但它不起作用:

FormatTime,datein,'01 / Jan / 1999',dd / MMM / yyyy

GuiControl ,, myDate,%datein%


dateparse函数有效,但是,我如何将值设置为datetime?

这是我的代码:

Gui, Add, DateTime, vmyDate, dd/MMM/yyyy
newdate := DateParse("Jan 1 1999")
FormatTime, test, % newdate, dd/MMM/yyyy
GuiControl,, myDate, %test%

1 个答案:

答案 0 :(得分:0)

幸运的是,有人已为此目的写了Date Parsing Function

该函数采用大量日期格式并以YYYYMMDDHH24MISS格式返回。然后,您可以将该值与FormatTime一起使用。

以下是一些示例用法:

newdate := DateParse("Jan 1 1999")
FormatTime, test, % newdate, dd/MMM/yyyy
msgbox % test

DateParse(str) {
    static e2 = "i)(?:(\d{1,2}+)[\s\.\-\/,]+)?(\d{1,2}|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*)[\s\.\-\/,]+(\d{2,4})"
    str := RegExReplace(str, "((?:" . SubStr(e2, 42, 47) . ")\w*)(\s*)(\d{1,2})\b", "$3$2$1", "", 1)
    If RegExMatch(str, "i)^\s*(?:(\d{4})([\s\-:\/])(\d{1,2})\2(\d{1,2}))?"
        . "(?:\s*[T\s](\d{1,2})([\s\-:\/])(\d{1,2})(?:\6(\d{1,2})\s*(?:(Z)|(\+|\-)?"
        . "(\d{1,2})\6(\d{1,2})(?:\6(\d{1,2}))?)?)?)?\s*$", i)
        d3 := i1, d2 := i3, d1 := i4, t1 := i5, t2 := i7, t3 := i8
    Else If !RegExMatch(str, "^\W*(\d{1,2}+)(\d{2})\W*$", t)
        RegExMatch(str, "i)(\d{1,2})\s*:\s*(\d{1,2})(?:\s*(\d{1,2}))?(?:\s*([ap]m))?", t)
            , RegExMatch(str, e2, d)
    f = %A_FormatFloat%
    SetFormat, Float, 02.0
    d := (d3 ? (StrLen(d3) = 2 ? 20 : "") . d3 : A_YYYY)
        . ((d2 := d2 + 0 ? d2 : (InStr(e2, SubStr(d2, 1, 3)) - 40) // 4 + 1.0) > 0
            ? d2 + 0.0 : A_MM) . ((d1 += 0.0) ? d1 : A_DD) . t1
            + (t1 = 12 ? t4 = "am" ? -12.0 : 0.0 : t4 = "am" ? 0.0 : 12.0) . t2 + 0.0 . t3 + 0.0
    SetFormat, Float, %f%
    Return, d
}