我必须更改DateTime格式. [英] I have to change DateTime format.
本文介绍了我必须更改DateTime格式.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我制作了一个简单的Employee Presence应用程序(实际上,我制作的每个应用程序都在发生这种情况.我是C#的新手.)当我尝试在其他计算机上运行它时,它没有运行,并给出了无效的dateTime错误.所以我更改了与我相同的那台机器的DateTime格式.运行成功.那我该怎么办.我不想在每台计算机上更改日期时间格式.
I made a simple Employee Presence Application (actually this is happening with every applications I make. I am new to C#.). When I tried to run it on other machine it didn''t run and gave an error of Invalid dateTime. So I changed DateTime Format of that machine same as mine. It ran successfully. So what can I do. I don''t want to change datetime format on every machines.
推荐答案
问题尚不清楚.使用.NET,您可以读取任何格式的时间,并在输出时产生任何格式.请查看方法Parse
,ParseExact
,TryParse
,TryParseExact
和ToString
的数量:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ].
有关格式说明符,请参见:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ].
此外,请确保仅在确实需要时才从字符串解析并输出数据到字符串.我看到很多问题,查询者倾向于使用表示数据的字符串而不是数据本身.这是完全错误的方法.
—SA
The problem is not clear. With .NET, you can read time in any format and produce any format on output. Please see the number of methodsParse
,ParseExact
,TryParse
,TryParseExact
andToString
:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].
For format specifiers, please see:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].
Besides, make sure you parse from string and output data to string only when it is really required. I saw many questions where the inquirers tend to work with strings representing data instead of data itself. This is totally wrong approach.
—SA
这篇关于我必须更改DateTime格式.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文