日期或日期时间对象独立于页面区域性

发布于 2024-10-09 15:57:56 字数 554 浏览 8 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏の忆 2024-10-16 15:57:56

您应该将日期作为其本机类型而不是字符串存储在数据库中。当你获取它时,你应该格式化它。

You should store the date in the db as its native type, not a string. When you fetch it you should format it then.

人事已非 2024-10-16 15:57:56

为什么不在插入/更新操作之前转换 SQL 中的日期?
例如

SELECT convert(varchar, getdate(), 101) will give you date in mm/dd/yyyy format.

Sql 转换

Why don't you convert your date in sql before insert/update operation?
e.g.

SELECT convert(varchar, getdate(), 101) will give you date in mm/dd/yyyy format.

Sql Convert

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文