转换文件名的日期



我在将日期保存为Excel文档时遇到了问题。例如,去掉"/"和/或将其替换为"-"

Dim strDate
Dim intLen
Dim test
Dim testArray
strDate = Date
test = CStr(strDate)
testArray = Split(test)
intLen = Len(test)
For i =  0 To intLen
    if testArray(i) = "/" Then
        testArray(i) = "-"
    End If
Next
'Replace test, "/", "_"
For i =  0 To 3
    Wscript.Echo testArray(i)
Next

objExcel.ActiveWorkBook.SaveAs "C:Inventory Script" & intLen & ".xls"
objExcel.Close
objExcel.Quit

我试着让我们更换,因为这似乎是显而易见的答案,但毫无效果。起初我以为这是因为它不是字符串类型,但它仍然没有任何作用。

然后,我尝试用老派的方法,将字符串作为数组进行迭代并手动替换,但没有成功。

目前没有生成任何错误,Wscript。Echo testArray(i)正在输出2015年11月17日,这对我来说很奇怪,它正在输出。

Dim strDate
Dim intLen
Dim test
Dim testArray
strDate = Date
test = CStr(strDate)
'''''' test= join(Split(test,"/"),"_")
'''''' test= join(Split(test,"-"),"_")
test= replace(test,"/","_")
test= replace(test,"-","_")
Wscript.echo test

最新更新