寻找日期时间格式之间的差异。 [英] Looking for difference between datetime formats.

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

问题描述

有什么区别



a。 String.Format({0:g},dt);



VS.



b 。 DateTime x;

x.Tostring(g);



在多文化功能的情况下使用哪一个。由于多文化功能,我不想要硬编码。



 MM / DD / YYYY HH:MM AM或PM 





我用Google搜索并搜索了msdn但是仍然不清楚。

解决方案

没有任何差异。 String.Format({0:g},dt)实际上会调用 dt.ToString(g)



DateTime 实现 IFormattable [ ^ ]界面, String.Format 将最终调用 IFormattable.ToString [ ^ ]方法。


你可以参考这个,这里提供的解决方案非常类似于你的查询。



http://stackoverflow.com / questions / 7874869 / datetime-issue-when-the-server-of-the-server-is-different-on-different-serve [ ^ ]



更多参考资料。

http://www.dotnetperls .com / datetime-format [ ^ ]

What is the difference between

a. String.Format("{0:g}",dt);

VS.

b. DateTime x;
x.Tostring("g");

which one to use in case of multi-culture functionality. I dont want to hard code due to multi-culture functionality.

MM/DD/YYYY HH:MM AM or PM



I Googled and searched msdn however still not clear.

解决方案

There isn't any difference. String.Format("{0:g}", dt) will actually call dt.ToString("g")

DateTime implements the IFormattable[^] interface, and String.Format will end up calling the IFormattable.ToString[^] method.


You can refer this, the solution provided here closely resembles with your query.

http://stackoverflow.com/questions/7874869/datetime-issue-when-global-culture-of-the-server-is-different-on-different-serve[^]

More reference.
http://www.dotnetperls.com/datetime-format[^]


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

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