需要一个日期函数 C# 传入1988生成 1988-1-1传入1998-3 生成1998-3-1类似这样 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果认为DateTime 类的构造函数不行,则实现如下三个重载版本,呵呵。private DateTime GetDateTime(int year){ DateTime dt = new DataTime(year,1,1); return dt;}private DateTime GetDateTime(int year, int month){ DateTime dt = new DateTime(year, month, 1); return dt;}private DateTime GetDateTime(int year, int month, int day){ DateTime dt = new Datetime(year, month, day); return dt;} string[] formats = { "yyyy", "yyyy-M", "yyyy-M-d" };DateTime d1 = DateTime.ParseExact("1988", formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);DateTime d2 = DateTime.ParseExact("1998-3", formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);DateTime d3 = DateTime.ParseExact("1999-3-4", formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);Console.WriteLine(d1.ToString("yyyy-M-d"));Console.WriteLine(d2.ToString("yyyy-M-d"));Console.WriteLine(d3.ToString("yyyy-M-d")); private string GetYearMonthDay(string yearMonth) { if(yearMonth.IndexOf("-")>-1) return yearMonth+"-1"; else return yearMonth+"-1-1"; } OA邮件 日历行程 新闻动态 简单返回json格式字符串的问题 winform里有相当于asp.net里的skin吗? winform 项目打包 许可协议 关于graphice.DrawString的空格 这样连数据库为何信息插入不到数据库中(在线等) 关于数据库插入数据不重复的问题 消息队列处理慢出现消息积压现象求解 網頁間參數傳遞問題 调用非windows api 该怎么办啊? 外网访问 DataGrid 翻页很慢 C#如何连接acess数据库
{
DateTime dt = new DataTime(year,1,1);
return dt;
}private DateTime GetDateTime(int year, int month)
{
DateTime dt = new DateTime(year, month, 1);
return dt;
}private DateTime GetDateTime(int year, int month, int day)
{
DateTime dt = new Datetime(year, month, day);
return dt;
}
DateTime d1 = DateTime.ParseExact("1988", formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
DateTime d2 = DateTime.ParseExact("1998-3", formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
DateTime d3 = DateTime.ParseExact("1999-3-4", formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
Console.WriteLine(d1.ToString("yyyy-M-d"));
Console.WriteLine(d2.ToString("yyyy-M-d"));
Console.WriteLine(d3.ToString("yyyy-M-d"));
{
if(yearMonth.IndexOf("-")>-1)
return yearMonth+"-1";
else return yearMonth+"-1-1";
}