Search

Tuesday, April 22, 2014
0 comments

How to add Hours in existing time in ASP.NET

1:43 AMTuesday, April 22, 2014

Introduction

Using AddHours method  you can add Hours in integer, Object will be updated with new date and time. This method is used where you want to calculate time after some time. Like Library management project. Lets take an simple example

<form id="form1" runat="server">
    <div>  
        <asp:Button ID="Button1"
        runat="server"
        BackColor="#66FFFF"
        onclick="Button1_Click"
        Text="Click" />  
    </div>
        <asp:Label ID="Label1"
        runat="server"
        BackColor="Yellow"></asp:Label>
    </form>
Code Behind
 protected void Button1_Click(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;          
            DateTime after3Hours = now.AddHours(3);            
            DateTime after4Hours = now.AddHours(4);
            Label1.Text = "present time = " + now.ToLongTimeString();
            Label1.Text += "<br /><br />";
            Label1.Text += "after added three hours with present time <br />";
            Label1.Text += after3Hours.ToLongTimeString();
            Label1.Text += "<br /><br />";
            Label1.Text += "after added four hours with present time <br />";
            Label1.Text += after4Hours.ToLongTimeString();

        }
 Code Generate the following Output
How to add Hours in existing time in ASP.NET

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top