asp.net中的日期和时间 [英] Date and Time in asp.net

查看:73
本文介绍了asp.net中的日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我需要5分钟后再返回一条消息,与系统日期进行比较.

假设现在的时间是上午11:50.我需要消息上次更新时间为21/04/2012 11:45 am.".

此消息应比系统时间少5分钟.

谢谢,

这是我的代码.



Dear Frnds,

i need a Message 5 min back compare to system date.

Suppose now the time is 11:50 am.. I need the message as Last updated at 21/04/2012 11:45 am.

this message should be 5 min less than system time.

Thanks,

This is my code.



//protected void UpdateTimer_Tick(object sender, EventArgs e)
    //{
    //    Label3.Text = "Last Updated at : " + DateTime.Now.ToLongTimeString();
    //}

推荐答案

只需使用此代码即可.
Just Use this code..

protected void UpdateTimer_Tick(object sender, EventArgs e)
{
    Label3.Text = "Last Updated at : " 
         + DateTime.Now.AddMinutes(-5).ToLongTimeString();
}


使用此

DateTime.Now.AddMinutes(-5);
看到这个
http://wiki.lessthandot.com/index.php/ASP.NET:_Simple_date_and_time_methods [ ^ ]
Use this

DateTime.Now.AddMinutes(-5);
See this
http://wiki.lessthandot.com/index.php/ASP.NET:_Simple_date_and_time_methods[^]


DateTime的AddMinutes方法添加参数中指定的分钟数.如果它是负数,则减去该分钟数.

所以,
DateTime.Now.AddMinutes(-5)将用于此目的.

希望这会有所帮助.
DateTime''s AddMinutes method Adds the No. of minutes specified in parameter. If it''s a Negative Number then it subtracts that No. of minutes.

So,
DateTime.Now.AddMinutes(-5) will serve the purpose.

Hope this helps.


这篇关于asp.net中的日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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