Comon日期时间格式 [英] Comon Date Time Format

查看:107
本文介绍了Comon日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个VB.net程序,它将日期和时间存储为sql表的日期之一。



i use



Hi All,

I have an VB.net program which stores date and time as one of the date to the sql table.

i use

date.today





程序转换为exe并且许多pc使用它。这里的问题是不同的pc有不同的时间和日期格式。当我每天报告时,报告错过了很多数据。



例如我每天报告



填充所有项目,其中date =



the program is converted to exe and many pcs use it. The problem here is different pc has different time and date formats. When i take report on daily basis the report misses many data.

for example i take report on daily basis by

populate all items where date =

date.today

。如果格式不同,则忽略数据。它使用我的系统格式搜索数据。



怎么过来这个?

. if the format is different it ignores the data. it search the data with my system format.

How to over come this??

推荐答案

你的整个方法都错了。日期/时间是普遍的概念,并没有真正有任何不同的格式。如果您尝试以字符串的形式存储数据,则格式会起作用。你不应该。说到数据库,使用DATE数据类型存储此时间数据,这实际上代表一个时间点,而不仅仅是日期(因此类型的名称令人困惑)。只有当你想在屏幕上显示日期/时间时才需要字符串,但是你可以使用适当的格式:

http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/az4se3k1.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]。



(另见所有其他 System.DateTime.ToString / Parse / TryParse / ParseExact / TryParseExact 方法。)



Genera现在,使用字符串表示数据而不是数据本身的趋势是一个非常常见的初学者问题。不要重复这个错误,尝试使用数据。



-SA
Your whole approach is wrong. Date/time is the universal notion and does not really have any different formats. The formats come into play if you try to store data in the form of strings. You should not. When it comes to databases, store this time data using DATE datatype, which actually represent a point in time, not just date (so the name of type is confusing). And you will need strings only if you want to present date/time on screen, but then you can use appropriate formatting:
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

(See also all other System.DateTime.ToString/Parse/TryParse/ParseExact/TryParseExact methods.)

Generally, the trend to work with string representing data instead of data itself is a very common beginner's problem these days. Don't repeat this mistake, try to work with data.

—SA


这篇关于Comon日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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