English 中文(简体)
如何从规定日期起一年内获得天数总数
原标题:How to get the total number of days in a year from the given date
  • 时间:2012-05-08 09:15:54
  •  标签:
  • c#
  • asp.net

我愿从规定日期起一年中获得总天数。 用户提供的<代码>04-01-2011(MM-DD-YYYYYY) 我想找到剩下的几天。 如何做到这一点。

最佳回答

让我说,今天是:

var user = "05-08-2012";
var date = DateTime.ParseExact(user, "MM-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var lastdate = new DateTime(date.Year, 12, 31);
var diff = lastdate - date;

<编码>diff.TotalDays 日数。 还包括该年度的最后日期。

问题回答

也许只是:

DateTime.IsLeapYear(inputYear) ? 366 : 365

the

intdayLeft = 新的日期(Datetime.Now. Year, 12, 31)。 DayOf Year - 日期:Now.DayOf Year;

new Daytime (suppliedDate. Year, 12, 31).Subtract (suppliedDate).TotalDays

我认为,你应该像现在这样努力。

 DateTime startTime = DateTime.Now;

 DateTime endTime = DateTime.Now.AddSeconds( 75 );

 TimeSpan span = endTime.Subtract ( startTime );
 Console.WriteLine( "Time Difference (seconds): " + span.Seconds );
 Console.WriteLine( "Time Difference (minutes): " + span.Minutes );
 Console.WriteLine( "Time Difference (hours): " + span.Hours );
 Console.WriteLine( "Time Difference (days): " + span.Days );

选择一个起步日期,增加一年半,然后从起算结束日期,在两个日期之间,你休息日总数。

var beginOfYear = new DateTime(2000, 01, 01, 0, 0, 0, DateTimeKind.Local);
var endOfYear = beginOfYear.AddYears(1).AddDays(-1);
var daysOfYear = endOfYear.Subtract(beginOfYear).TotalDays;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签