我正在处理前一位开发人员的代码。此代码已设置SystemTime。 有没有办法以这种格式获得今天的日期和零下30天?
以下代码:
www.myurl.com/page?psid=USERPSID
答案 0 :(得分:0)
建立原生日期&时间,添加-30天,格式化为字符串:
utcInIsoFormat = Format$(DateAdd("d", -30, _
DateSerial(st.wYear, st.wMonth, st.wDay) _
+ TimeSerial(st.wHour, st.wMinute, st.wSecond)), "yyyy-mm-ddThh:nn:ssZ")
答案 1 :(得分:0)
SYSTEMTIME似乎是代码中其他位置定义的自定义类型。它不是Access VBA中可用的标准类型。因此,要有效地使用它,您需要找到定义。此外,GetSystemTime也可能是您的代码独有的自定义功能。以下是类似类型的示例定义,但可能不完全是您系统中实现的内容:http://custom-designed-databases.com/wordpress/2011/get-milliseconds-or-seconds-from-system-time-with-vba/
那就是说,系统时间会指Windows系统时间。您还可以在VBA中使用Now()函数获得时间。 (https://msdn.microsoft.com/en-us/library/office/gg278671.aspx)这将返回一个类型为Date的变量,该变量等于整数表示天数而小数表示时间的数字。在今天之前30天获得的一个例子是:
Dim lastMonth as Date
Dim formattedDate as String
lastMonth = Now() - 30
formattedDate = Format(lastMonth, "yyyy-mm-ddThh:nn:ssZ")
答案 2 :(得分:0)
DateSerial乐意接受负数日计数。因此:
Public Function IsoDateMinus30() As Date
Dim st As SYSTEMTIME
Dim Result As Date
' Get the local date and time
GetSystemTime st
Result = DateSerial(st.wYear, st.wMonth, st.wDay - 30)
' To include time:
'
' Result = _
' DateSerial(st.wYear, st.wMonth, st.wDay - 30) + _
' TimeSerial(st.wHour, st.wMinute, st.wSecond)
IsoDateMinus30 = Result
End Function