0

Can anyone tell me how to set '01/Jan/1999' to a DateTime?

I've tried this but it didn't work:

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

GuiControl,, myDate, %datein%


The dateparse function worked but, how am I going to set the value to the datetime?

Here is my code:

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

1 に答える 1

0

幸運なことに、誰かがこの目的のために すでに日付解析関数を書いています。

この関数は多数の日付形式を取り、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
}
于 2013-10-18T12:46:49.700 に答える