我们如何获得系统时间? [英] how can we get the system time?

查看:84
本文介绍了我们如何获得系统时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

label5.Text = DateTime.Now.ToLongTimeString();这会带来长远的价值.

label6.Text = DateTime.Now.ToShortTimeString();
这也将给出相同的长时间值.如何获得短时间值(仅时间值而不是日期)?

1/1/1900 3:34:00 AM都是label5和label6

label5.Text = DateTime.Now.ToLongTimeString(); this would give a long value.

label6.Text = DateTime.Now.ToShortTimeString();
this would also give the same long value of time.how can we get a short time value(only the time value not the date)?

1/1/1900 3:34:00 AM would be the result for both label5 n label6

推荐答案

的结果.为了更进一步,我将说没有日期与时间之类的东西. (类型名称DateTime令人困惑,但这是由于传统.)其他所有内容都与它的字符串表示形式有关.您需要使用时间,而不是字符串表示形式.您不应使用字符串表示形式进行任何计算.仅在需要在文本文件的屏幕上显示时间字符串时才应使用它.

因此,跳过中间DateTime值(例如DateTime.Now.ToLongTimeString)的单个表达式在任何地方都几乎没有用.

方法集System.DateTime.ToString提供了根据不同的UI文化和任何可想到的要求格式化时间的全面方法.
参见:
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
There is no such thing as short or long time. To make a step further, I''ll say there is no such thing as date vs time. (The type name DateTime is confusing, but this is due to tradition.) There is just time; everything else is related to its string representation. You need to work with time, not with its string representation. You should not do any calculations with string representation. You should only use it when you need to show a time string on screen of in text file.

Therefore, a single expression skipping intermediate DateTime value like DateTime.Now.ToLongTimeString is hardly useful anywhere.

A comprehensive ways of formatting time according to different UI cultures and any thinkable requirements is provided by the set of methods System.DateTime.ToString.

See:
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


u可以通过创建日期时间函数的对象自己输入所需的格式.

datatime obj = datetime.now;

字符串datentime;

datentime = obj.tostring("HH:MM:SS"); //输出为7:30:55
("HH:MM tt"); /output是7:30 pm
u can input the desired format yourself by creating a object of datetime function.

datatime obj= datetime.now;

string datentime;

datentime= obj.tostring(" HH:MM:SS "); //output is 7:30:55
("HH:MM tt"); /output is 7:30 pm


plz再次检查它仅给出时间:例如6:51 AM
label1.Text = DateTime.Now.ToShortTimeString();
plz do check it again it gives only time : eg 6:51 AM
label1.Text = DateTime.Now.ToShortTimeString() ;


这篇关于我们如何获得系统时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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