所有类型区域设置的通用DateTime [英] Common DateTime for all type of regional setting

查看:61
本文介绍了所有类型区域设置的通用DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想在c#3.0中实现这样一个通用的DateTime,它可以处理任何区域设置并且也兼容MS-SQL Server2005.我的代码仅适用于特定的区域设置.

有什么主意吗?


谢谢,

--- Anil Kumar Bhakta

Hi,
I want to implement such a common DateTime in c# 3.0 which should handle any regional setting and also compatible for MS-SQL Server 2005. My code works fine for specific regional setting only.

Is there any idea.


Thanks,

--- Anil Kumar Bhakta

推荐答案

使用DateTime:它与区域性无关,只要您将其作为参数而不是参数传递给SQL,SQL也会理解.字符串版本(为避免SQL注入攻击,您还是可以这样做吗?)

仅当出于显示或其他原因将日期转换为字符串时,日期才取决于区域性.
Use a DateTime: it is culture independent, and SQL understands it as well, provided you pass it over as a parameter rather than a string version (which you would do anyway to avoid SQL Injection attacks, wouldn''t you?)

A date only becomes culture dependent when you convert it to a string for display or other reasons.


使用System.DateTime结构并在UTC中工作.请参阅 http://msdn.microsoft.com/en-us/library/system.datetime.aspx [^ ] .您始终可以在每个客户端使用当地时区表示时间.

—SA
Use System.DateTime structure and work in UTC. See http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^]. You can always express time in local time zone on each client''s side.

—SA


这篇关于所有类型区域设置的通用DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆