时间显示-----------------秒 [英] time display----------------- seconds

查看:53
本文介绍了时间显示-----------------秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何只显示秒......我不想显示整个时间......(hh:mm:ss)...我只想要秒...... ???在我的asp.net wep页面 ..如何从DateTime.Now.ToLongTimeString()获取秒数请帮助我:)。

解决方案

无论秒数是多少,这都不是时间;最有可能的是,这是一个 TimeSpan

http://msdn.microsoft.com/en-us/library/system.timespan.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.timespan.totalseconds.aspx [ ^ ]。



这取决于你如何获得时间跨度,但最常见的是,这是两个时间点之间的差异:

 DateTime begin =  //   ...  
// ...时间通过
DateTime end = // ...
TimeSpan duration = end - pass; // 更喜欢使用运算符而不是函数





如果由于一些奇怪的原因,你需要显示一段时间的秒数,你应该明白秒将循环。你可以展示你想要的任何东西,它只是格式和文化的问题:

http://msdn.microsoft.com/en-us/library/ht77y576.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/az4se3k1.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]。



我当然需要学习的主要内容当然是这: Microsoft Q209354



-SA


在这里你去: -



< pre lang =c#> DateTime dtNow = DateTime.Now;
CultureInfo cInfo = new CultureInfo( zh-CN -US);
DateTimeFormatInfo dtInfo = cInfo.DateTimeFormat;
dtInfo.ShortTimePattern = ss;
yourlbl.Text = dtNow.ToString( t,cInfo);





不要忘记使用System.Globalization添加名称空间;



如果你想要回答这个答案,请写下原因。


祝你好运。


请试试这个!

这是获得''秒'的最简单形式

 yourlabel.Text = DateTime.Now.ToString(  ss); 


How to display only seconds.... i dont want to display whole time...(hh:mm:ss)... i want only seconds..????? in my asp.net wep page .. how to get seconds from "DateTime.Now.ToLongTimeString()" pls help me :)..

解决方案

Whatever the seconds are, this is hardly time; most likely, this is a TimeSpan:
http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^],
http://msdn.microsoft.com/en-us/library/system.timespan.totalseconds.aspx[^].

It''s up to you how you get the time span, but most usually, this is a difference between two points of time:

DateTime begin = //...
// ... time passes
DateTime end = //...
TimeSpan duration = end - pass; // prefer using operators rather then functions



If, by some weird reason, you need to show seconds of some time, you should understand that the seconds will cycle. You can show whatever you want, it''s merely the matter of formatting and culture:
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^],
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

My the main thing you need to learn is of course this: Microsoft Q209354.

—SA


Here you go :-

DateTime dtNow = DateTime.Now;
CultureInfo cInfo = new CultureInfo("en-US");
DateTimeFormatInfo dtInfo = cInfo.DateTimeFormat;
dtInfo.ShortTimePattern = "ss";
yourlbl.Text = dtNow.ToString("t", cInfo);



Don''t forget to add namespace using System.Globalization;

And If you want to downvote this answer please write the reason.

Good luck.


hi ram, try this !
This is the simplest form to get ''seconds'' only

yourlabel.Text=DateTime.Now.ToString("ss");


这篇关于时间显示-----------------秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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