面试,求救! 题目是让用户输入日期,之后判断给定的一天是这一年的第几天,拜托各位大仙了... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DateTime da = DateTime.Parse("日期");int days =da.DayOfYear; 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("输入的日期格式不正确!"); } } }} 参考http://topic.csdn.net/u/20100730/19/2a974b28-cd10-4aec-aaa9-d6c0e3c37d5a.html 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(); 急!急!GridView是代码分页的,要全部导出EXCEL,而不是gridview第一页 求助!控件没有被锁定,但是却不可选了 C# 内的SQL语句问题!!请大家帮忙! 怎么样获得windows属性页里的网址 如何拆分一个字符串 对VS2005自带的SQLServerExpress问题 求算法 求购:计算机网络安全软件 使用sharepoint的web services时总时报错??? 请问哪里有visual sourcesafe客户端下载 未处理FormatException 输入字符串的格式不正确 repeater 嵌套
DateTime da = DateTime.Parse("日期");int days =da.DayOfYear;
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("输入的日期格式不正确!");
}
}
}
}
http://topic.csdn.net/u/20100730/19/2a974b28-cd10-4aec-aaa9-d6c0e3c37d5a.html
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();