FormatTime返回今天的日期,而不是变量的实际日期

问题描述

我从正则表达式中提取一个时间戳。这将是原始格式:YYYYMMDD

文档中没有时间戳似乎是可以接受的。我尝试了有无。

我只想将其转换为MMMDD,但是它只输出我尝试过的所有内容的今天日期。所以我一定缺少一些重要的东西。

regexmatch(file_name,"O) (202[0-9][0]?[1]?\d{1}\d{2})",diag_date)
; diag_date[1] in all my testing has been 20200831
msgBox % "Unformatted Date: " diag_date[1] 
FormatTime,diag_date,diag_date[1],MMMdd
msgBox % "Formatted Date: " diag_date

-更简单的测试-

unformatted := "20200831"
FormatTime,formatted,unformatted,MMMdd
msgBox % formatted
; still outputs today's date.

即使匹配的日期是另一个日期(例如20200831),最后一个msgBox仍会返回今天的日期

解决方法

您没有在第二个参数上强制使用表达式。因此,它只是解释您传入了无效的时间戳。

unformatted := "20200831"
FormatTime,formatted,% unformatted,MMMdd
msgbox % formatted