如何使用vbscript创建XML的dateTime格式?

时间:2012-10-04 17:54:26

标签: datetime vbscript

我需要以下列格式创建提取的日期和时间。

extractDate='2011-10-18T12:00:00.000000'

使用vbscript / asp3执行此操作的最佳方法是什么?我只是考虑对.000000的末尾部分进行硬编码,因为这不是一场赛马LOL

感谢。

到目前为止,我开始有类似的事情;

xmlDateTime = FormatDateTime(Now(),0)
xmlDateTime = Replace(xmlDateTime, " PM", "")
xmlDateTime = Replace(xmlDateTime, " AM", "")
Response.Write xmlDateTime & "<br>"

更新:

我的潜在解决方案:

xmlDateTime = FormatDateTime(Now(),0)
xmlDateTime = Replace(xmlDateTime, " PM", "")
xmlDateTime = Replace(xmlDateTime, " AM", "")
Response.Write xmlDateTime & "<br>"
splitDateTime = Split(xmlDateTime, " ")

xmlDate = splitDateTime(0)
xmlTime = splitDateTime(1)

strYear = DatePart("yyyy",xmlDate)
strMonth = DatePart("m",xmlDate)
strDay = DatePart("d",xmlDate)


Response.Write strYear & "<br>"
Response.Write strMonth & "<br>"
Response.Write strDay & "<br>"

xmlDateTime = strYear & "-" & strMonth & "-" & strDay & "T" & xmlTime & ".000000"
Response.write xmlDateTime & "<br>"

1 个答案:

答案 0 :(得分:3)

您需要手动构建日期字符串。

Function dd(str)
  dd = Right("0" & str, 2)
End Function

d = Now
extractDate = Year(d) & "-" & dd(Month(d)) & "-" & dd(Day(d)) & "T" _
  & dd(Hour(d)) & ":" & dd(Minute(d)) & ":" & dd(Second(d)) & ".000000"