日期时间问题,PC可以返回不同的格式吗? [英] Date Time Question, Can the PC return different format?

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

问题描述

大家好,



我需要一些测试的当前时间,所以我使用的是

 Time = DateAndTime.Now.ToString 
TimeOnly = Time.Substring( 11 5

为了得到时间,因为我不需要这部分中的日期,这在这里工作正常,但在客户系统上看起来10:09变为0:09 DateAndTime是否从PC Windows时间工作,不它(?),我可以在子字符串中过早修剪吗?

格伦

解决方案

我不会做字符串操作但是像这个:



 var result = string.Format({0}:{1},DateTime.Now.Hour,DateTime.Now 。分钟); 


你不需要修剪任何东西。您只需要处理数据本身,而不是表示数据的字符串。

请参阅属性:http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ]。



这就是你的位置只能提取时间。



你可以按照你想要的方式控制时间格式。查看所有 System.DateTime.ToString 方法。格式可以是自定义的,取决于文化或系统设置等。



另请参见格式说明符:

http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs .110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/8kb3ddd4(v = vs.110).aspx [ ^ ]。



-SA

Hi All,

I need the current time of some tests so I was using

Time = DateAndTime.Now.ToString
TimeOnly = Time.Substring(11, 5)

To get the time only as I don't need the date in this part, this works fine here but on the customer system it appears that 10:09 becomes 0:09 does DateAndTime works from the PC Windows time, doesn't it(?), could I be trimming too early in the substring ?
Glenn

解决方案

I would not do string operations but something like this:

var result = string.Format("{0}:{1}", DateTime.Now.Hour, DateTime.Now.Minute);


You don't need to trim anything. You just need to work with data itself, not string representing data.
Please see, look at the properties: http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

This is where you can extract time only.

And you can control the formatting of time as string the way you want. Look at all System.DateTime.ToString methods. The format can be custom, depend on culture or system settings, and so on.

See also format specifiers:
http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^].

—SA


这篇关于日期时间问题,PC可以返回不同的格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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