如何从给定的日期得到一年的天总数 [英] How to get the total number of days in a year from the given date

查看:170
本文介绍了如何从给定的日期得到一年的天总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得天的总数在一年内从给定日期离开..假设,如果一个用户给 04-01-2011(MM-DD-YYYY)我想找到离开了剩下的日子。如何做到这一点..

I would like to get the total number of days in a year left from the given date .. Assume if a user gives 04-01-2011(MM-DD-YYYY) I would like to find the remaining days left. How to do this..

推荐答案

让我们说今天的日期是:

Let's say the date is today:

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 中包含的天数(感谢@Tung)。 lastdate 还包含一年的最后日期。

diff.TotalDays contains the number of days (thanks @Tung). lastdate also contains the last date for the year.

这篇关于如何从给定的日期得到一年的天总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆