结构类似于DateTime.Now [英] Structure similar to DateTime.Now

查看:116
本文介绍了结构类似于DateTime.Now的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试创建带有图像的数字时钟.请帮助我创建一个类似于DateTime.Now的结构,该结构的成员保存当前时间的每一位数.基本上,我需要从我的自定义结构中获取DateTime.Now.Seconds%10和DateTime.Now.Seconds/10,类似地花费数小时和数分钟.

说,我想访问

mystruct.SecondDigit1;
mystruct.SecondDigit2;
mystruct.minuteDigit1;
mystruct.minuteDigit2;
以此类推

Hi,
I am trying to create a digital clock with images.Please help me to create a structure similar to DateTime.Now which has members that hold each digits of current time. Basically,I need to get DateTime.Now.Seconds%10 and DateTime.Now.Seconds/10 from my custom structure,similarly for hours and minutes.

say, i would like to access

mystruct.SecondDigit1;
mystruct.SecondDigit2;
mystruct.minuteDigit1;
mystruct.minuteDigit2;
and so on

推荐答案

我和理查德(Richard)在一起-尽管您可以这样做,但您确实不需要这样做,尽管您可以从DateTime派生一个类并添加新属性.

重要说明:请勿重复使用DateTime.Now.始终将其复制到时间实例:
I''m with Richard - you don''t really need to do that, although you can, just derive a class from DateTime and add the new properties.

An important note: Do not use DateTime.Now repeatedly. Always copy it to an instance of time:
DateTime now = DateTime.Now;

,并使用它作为DateTime.如果时间更改,现在可以在两个调用之间进行更改.根据您更新时钟的时间,这可能会使您的时钟耗费大量的时间.

and use that, as DateTime.Now can change between two calls if the time changes. This could put your clock out by a huge amount, depending on the time at which you update it...


显而易见的答案是创建一个新的结构并从中填充详细信息.如上所述,DateTime.但是我不确定为什么要这样做,为什么不直接从DateTime取值呢?
The obvious answer is to create a new structure and fill in the details from a DateTime as described above. But I''m not sure why you wish to do it this way, why not just take the values direct from the DateTime?


您可以像这样获取时间字符串:

You can get your time string like this:

string timeStr = DateTime.Now.ToString("HH:mm");


这篇关于结构类似于DateTime.Now的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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