Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Date Time Operations, How to check that year is leap or not, is time is in range of day light saving time or not and getting date as a day of weak and year using “Date Time” ” Class” in C# Part4

Author: Zunnair
Download Source Code : 877_source.zip

In this article you will learn that how we can check that year is leap or not, is time is in range of day light saving time or not and getting date as a day of weak and year using “Date Time” Class”.

 

In my previous articles I discussed how to get time and date from system and also their components individually. Those articles will help you to understand this article more.
Is Leap Year:
Every year we see that the month of February has twenty eight days in it but February also has twenty nine days in it. The year in which it has twenty nine days that year is called leap year. This year comes after four years. So in this article you will learn that how can we check that year is leap or not. For this purpose Date Time class provides us a static function named is Leap Year (). This function takes year as an integer and returns Boolean that year is leap or not. If the given year is leap year, it returns true else it returns false.
To demonstrate make a window application. Drag one text box and one button on the form. Press button you will get the result in text box.
Now write the following code on button click event
C#
private void btn_LeapYear_Click(object sender, EventArgs e)
        {
            int year = 2008;
            bool b;
            b = DateTime.IsLeapYear(year);
            string str = b.ToString();
            txt_Result1.Text = str;
        }
VB
Private Sub btn_LeapYear_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim year As Integer = 2008
        Dim b As Boolean
        b = DateTime.IsLeapYear(year)
        Dim str As String = b.ToString()
        txt_Result1.Text = str
    End Sub
This simple code tells that given year is leap or not.
 
Is In Day Light Saving Time Range:
Date Time class also provides us a facility to check that the given time is in the day light saving time range or not, in the current time zone. For this purpose Date time class provides us a function named is day light saving time (). This function is called by the object of date time class because it is a non static function. This function tells about that time which is stored in object through which function is called. This function does not take any parameter and returns Boolean value. If time is in range of day light saving time than it returns true else it returns false.
To demonstrate make a window application. Drag one text box and one button on the form. Press button you will get the result in text box.
Now write the following code on button click event
C#
private void btn_DayLight_Click(object sender, EventArgs e)
        {
            DateTime obj = new DateTime();
            obj = DateTime.Now;
            bool b;
            b = obj.IsDaylightSavingTime();
            txt_Result2.Text = b.ToString();
        }
VB
Private Sub btn_DayLight_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim obj As New DateTime()
        obj = DateTime.Now
        Dim b As Boolean
        b = obj.IsDaylightSavingTime()
        txt_Result2.Text = b.ToString()
    End Sub
This simple code tells that given time belongs to day light saving time range of current zone or not.
Day of Weak:
Date Time provides us a facility that we can check that given date is what day of weak. For this purpose Date Time class provides us a property named day of weak. This property returns an enumeration named day of weak. This enumeration has the name of seven days of weak so it tells us that which day it is.
To demonstrate make a window application. Drag one text box and one button on the form. Press button you will get the result in text box.
Now write the following code on button click event
C#
private void btn_weak_Click(object sender, EventArgs e)
        {
            DateTime obj = new DateTime();
            obj = DateTime.Now;
            DayOfWeek en;
            en = obj.DayOfWeek;
            string str;
            str = en.ToString();
            txt_Result3.Text = str;
        }
VB
Private Sub btn_weak_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim obj As New DateTime()
        obj = DateTime.Now
        Dim en As DayOfWeek
        en = obj.DayOfWeek
        Dim str As String
        str = en.ToString()
        txt_Result3.Text = str
    End Sub
This simple code tells you the day of weak according to given date.
Day of Year:
Date Time provides us a facility that we can check that given date is what day of year. For this purpose Date Time class provides us a property named day of year. This property returns an integer. As we know that a year has 365 days. So the integer returns by the property tells us that what number day has gotten out 365 according to the given date.
To demonstrate make a window application. Drag one text box and one button on the form. Press button you will get the result in text box.
Now write the following code on button click event
C#
private void btn_dayyear_Click(object sender, EventArgs e)
        {
            DateTime obj = new DateTime();
            obj = DateTime.Now;
            int year;
            year = obj.DayOfYear;
            string str;
            str = year.ToString();
            txt_Result4.Text = str;
        }
 
 
VB
Private Sub btn_dayyear_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim obj As New DateTime()
        obj = DateTime.Now
        Dim year As Integer
        year = obj.DayOfYear
        Dim str As String
        str = year.ToString()
        txt_Result4.Text = str
    End Sub
This simple code tells the day of year according to given year.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
 
            this.Text = "Devasp.Net Application";
        }
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
 
        Me.Text = "Devasp.Net Application"
 End Sub
 
This simple article tells how we can check that year is leap or not, is time is in range of day light saving time or not and getting date as a day of weak and year using “Date Time” Class” in C# and VB.
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Date Time Operations, How to add values or change values of components of date and time (day, month, year, minute, hour, second, millisecond) using “Date Time” ” Class” in C# (.net 2.0) Part3.

Disclaimer - Privacy
© 2002-2017 DevASP.net