有关日期、时间、星期
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace gettime
{
class Program
{
static void Main(string[] args)
{
string str = "2011/11/12 ";
int dt =Int32.Parse (DateTime.Parse(str).DayOfYear.ToString());//所表示的日期是该年中的第几天;
string week = DateTime.Parse(str).DayOfWeek.ToString("D");//所表示的日期是星期几(用数字表示);
string ss = string.Empty;
switch (week)
{
case "0":
ss = "星期日";
break;
case "1":
ss = "星期一";
break;
case "2":
ss = "星期二";
break;
case "3":
ss = "星期三";
break;
case "4":
ss = "星期四";
break;
case "5":
ss = "星期五";
break;
case "6":
ss = "星期六";
break;
default:
break;
}
Console.WriteLine(ss);
Console.WriteLine(dt);
Console.WriteLine(DateTime.DaysInMonth(2001, 2));
DateTime dt1 = DateTime.Parse("2011-3-12 18:39:00");
DateTime dt2 = DateTime.Parse("2003-3-12 18:51:00");
TimeSpan ts = (dt2 - dt1);
Console.WriteLine(ts.Days);//得到天数
Console.ReadLine();
}
}
}