字符串20100830如何转换成日期型啊,希望各位高手帮一下忙
解决方案 »
- 做了一个VS2010风格Toolbox型的抽屉控件...
- button的事件中如何取得button 的name属性值
- Csharp中 CreateCursor()怎么用
- 关于网络服务端转发信息的问题
- 求助 ConnectionString 属性尚未初始化。
- 怎么查看C#中类事件的代码啊?
- VB调用API函数的代码我改成C#调用后到SendMessage不返回1,失败了...
- microsoft application test center如何安装
- 用什么控件可以开发visual stadio.NET 中工具栏那样的界面
- 我想做到象C#界面中左侧工具箱那样形式的效果,可以吗?应该怎样的步骤?
- 能否获得类里面定义了多少个结构体?
- strA = "doc" 想判断是不是{ "pdf" , "doc" , "ppt" }中的一种,怎么写最好?
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入要计算的日期:");
string input = Console.ReadLine(); if (input.Length < 8)
{
Console.WriteLine("你输入的日期格式不正确");
}
else
{
DateTime dt = new DateTime();
dt = DateTime.Parse(input);
int year = dt.DayOfYear;
int mouth = dt.Month;
int day=dt.Day;
DateTime dt1 = new DateTime(year, 1, 1);
DateTime dt2 = new DateTime(year, mouth, day);
//int a = dt2.DayOfYear;
int days = (dt2 - dt1).Days + 1;
Console.WriteLine("你输入的日期是该年的第{0}天。", days.ToString());
}
Console.ReadLine();
}
}
}
public string FormatDateExact(object inValue)
{
if(inValue==null || inValue.ToString().Length==0)return "";
return DateTime.ParseExact(inValue.ToString(),"yyyyMMdd",System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy/MM/dd");
}
DateTime dt = DateTime.ParseExact("20100830", "yyyyMMdd",null); Console.WriteLine(dt);