题目是让用户输入日期,之后判断给定的一天是这一年的第几天,拜托各位大仙了...

解决方案 »

  1.   


    DateTime da = DateTime.Parse("日期");int days =da.DayOfYear;
      

  2.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("请输入日期:");
                string str = Console.ReadLine();
                DateTime dt = new DateTime();
                try
                {
                    dt = DateTime.Parse(str);
                    int year = dt.Year;
                    DateTime dt0 = new DateTime(year, 1, 1);
                    int days = (dt.Date - dt0.Date).Days + 1;
                    Console.WriteLine(string.Format("天数是:{0}。",days.ToString()));
                }
                catch
                {
                    Console.WriteLine("输入的日期格式不正确!");
                }
            }
        }
      

  3.   

    参考
    http://topic.csdn.net/u/20100730/19/2a974b28-cd10-4aec-aaa9-d6c0e3c37d5a.html
      

  4.   


    Console.WriteLine("*******{0}************","Welcome");
                Console.WriteLine("Please input the year:");
                String tempy = Console.ReadLine();
                Console.WriteLine("Please input the month:");
                String tempm = Console.ReadLine();
                Int32 year, month;            if (!Int32.TryParse(tempy, out year) || !Int32.TryParse(tempm, out month))
                    return;            Int32 days = DateTime.DaysInMonth(year, month);
                Int32 i = (Int32)(new DateTime(year, month, 1).DayOfWeek);            Console.WriteLine("Su".PadLeft(5) + "Mo".PadLeft(5) + "Tu".PadLeft(5) + "We".PadLeft(5) + "Th".PadLeft(5) + "Fr".PadLeft(5) + "Sa".PadLeft(5));            Int32 size = 0;
                Int32 k = 0;
                while (k < i)
                {
                    Console.Write("".PadLeft(5));
                    k++;
                    size++;
                }
                for (Int32 j = 1; j < days; j++)
                {
                    Console.Write(j.ToString().PadLeft(5));
                    size++;
                    if (size % 7 == 0)
                        Console.WriteLine();
                }
                Console.WriteLine();