Date and Time
* In Dot Net 'Now' is an object defined under "DateTime" library , is set the current time and date of your computer, general computer time is also set/display using Now object.
How can we display Time and Date in Dot Net-
1. Firstly, drag a button and a label control [ We will code inside the button click event and the Date & Time will be shown in the Label control ]
ex. -
//Date
Label1.Text = DateTime.Now.ToString("dd/MMMM/yyyy");
Label1.Text = DateTime.Now.ToString("dd");
//Day
Label1.Text = DateTime.Now.ToString("dddd");
//Month
Label1.Text = DateTime.Now.ToString("MMMM");
//Year
Label1.Text = DateTime.Now.ToString("yyyy");
//Time
Label1.Text = DateTime.Now.ToShortTimeString();
ADDING Hours/Months/Years to Current Time-
Implementation[We will use this function to show the user that the your subscription will gonna expire on that date]
Let's have a look-
Label1.Text = DateTime.Now.AddHours(5).ToShortTimeString();
Label1.Text = DateTime.Now.AddMonths(2).ToString("MMMM");
Label1.Text = DtaeTime.Now.AddYears(1).ToString("yyyy");
Comments
Post a Comment