在经典的asp中将字符串转换为日期时间

时间:2022-04-07 01:57:32

I have a string of "DD/MM/YYYY HH:MM:SS" which I need to transform to a date, the problem is the default conversion goes "MM/DD/YYYY HH:MM:SS" unless the day is >12 in which case it switches. I'd like to ensure that my day's go into the day portion of the date/time.

我有一串“DD / MM / YYYY HH:MM:SS”我需要转换为日期,问题是默认转换为“MM / DD / YYYY HH:MM:SS”,除非那天是>在这种情况下,它会切换。我想确保我的日子进入日期/时间的一天。

Is there an easy fix to this?

有一个简单的解决方案吗?

2 个解决方案

#1


' Parse a date in ISO 8601 "universal combined" format: YYYY-MM-DDTHH:MM:SSZ
' This function ALSO accepts SQL date format:  YYYY-MM-DD HH:MM:SS
Function CDateFromUniversal( s )

    CDateFromUniversal = CDate(Mid(s, 1, 10) & " " & Mid(s, 12, 8))

End Function

#2


use the format function

使用格式功能

this could do it too

这也可以做到

#1


' Parse a date in ISO 8601 "universal combined" format: YYYY-MM-DDTHH:MM:SSZ
' This function ALSO accepts SQL date format:  YYYY-MM-DD HH:MM:SS
Function CDateFromUniversal( s )

    CDateFromUniversal = CDate(Mid(s, 1, 10) & " " & Mid(s, 12, 8))

End Function

#2


use the format function

使用格式功能

this could do it too

这也可以做到