Pages

Search This Blog

Wednesday 28 May 2014

Displaying Date and Time

Hi friends, in this session I will show “How to display system date and time in your website”.

In many websites we will see the time and present date. Normally many people were interested to display time and date. So I had written this code....

Step1: (In file.aspx)
First to display time and date we need to create 2 labels. In 1st label we will display time and in 2nd label we will display date. Place the below code where you want to display.

<asp:Label ID="lb1" runat="server" Text="date"> </asp:Label> <br />

<asp:Label ID="lb2" runat="server" Text="time"> </asp:Label>

Step2: (In file.aspx.cs)

Place the below code on Page_Load (that means while loading the page itself it shows the date and time)

lb1.Text = System.DateTime.Now.ToString("yyyy/MM/dd");

lb2.Text = System.DateTime.Now.ToShortTimeString();

Note: We can change the date format as we want “dd/MM/YYYY” or “MM/DD/YYYY”

You can rate my class on right side top of my blog ....
                                                                          -Your's Santoshklpkl

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips Twitter Bird Gadget