Home » C#

C# | DateTime.DayOfYear Property with Example

DateTime.DayOfYear Property: Here, we are going to learn about the DayOfYear Property of DateTime class with example in C#.
Submitted by IncludeHelp, on October 24, 2019

DateTime.DayOfYear Property

DateTime.DayOfYear Property is used to get the time of the day of this object. It's a GET property of DateTime class.

Syntax:

    int DateTime.DayOfYear;

Return value:

The return type of this Property is int, It returns an integer value i.e. the day of the year of this object.

Example to demonstrate example of DateTime.DayOfYear Property

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //creating an object of DateTime class
            //and, initializing it with the current time 
            //using "Now"           
            DateTime dt = DateTime.Now;

            //getting the day of the year
            string dYear = dt.DayOfYear.ToString();

            //printing current date & time 
            Console.WriteLine("Current date & time is: " + dt.ToString());
            //printing the day of the week
            Console.WriteLine("The day of the year is : " + dYear);

            //just to print a new line
            Console.WriteLine();
        }
    }
}

Output

Current date & time is: 10/24/2019 8:31:15 AM
The day of the year is : 297





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.