日期或日期时间对象独立于页面区域性
Dim strTime as String = FomatDateForSave("28/12/2010")
Public Shared Function FormatDateForSave(ByVal strDate As String) As Date
FormatDateForSave = Date.ParseExact(strDate,'dd/MM/yyyy', System.Globalization.CultureInfo.InvariantCulture)
End Function
我期望 strTime 为“12/28/2010”....但它被转换为“28/12/2010”
....是当操作由 FormatDateForSave
执行时...它将其转换为“12/28/2010”...
但是当它返回时,它会再次转换为“12/28/2010”
< strong>我已将 Page.Culture 的日期设置为“dd/mm/yyyy”,并希望将值“mm/dd/yyyy”保存在数据库中。
Dim strTime as String = FomatDateForSave("28/12/2010")
Public Shared Function FormatDateForSave(ByVal strDate As String) As Date
FormatDateForSave = Date.ParseExact(strDate,'dd/MM/yyyy', System.Globalization.CultureInfo.InvariantCulture)
End Function
I am expecting strTime to be "12/28/2010" .... But its getting converted to "28/12/2010" ....
The thing is when the operation is performed by FormatDateForSave
... it converts it to "12/28/2010" ...
But when it is returned it is again converted to "12/28/2010"
I have set the Date for Page.Culture to be "dd/mm/yyyy" and want the value to be "mm/dd/yyyy" to be saved in DB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将日期作为其本机类型而不是字符串存储在数据库中。当你获取它时,你应该格式化它。
You should store the date in the db as its native type, not a string. When you fetch it you should format it then.
为什么不在插入/更新操作之前转换 SQL 中的日期?
例如
Sql 转换
Why don't you convert your date in sql before insert/update operation?
e.g.
Sql Convert