[英]How to get last month date from selected date in asp.net c#
所选日期为(txtfromdate):2016年12月1日
迄今为止:(txttodate):2016年12月31日
如何从2016年12月1日起在c#或javascript中计算2016年12月31日。
DateTime firstOfDecember = new DateTime(2016, 12, 1);
int lastDay = DateTime.DaysInMonth(firstOfDecember.Year, firstOfDecember.Month);
如果要创建等效于该月最后一天的DateTime对象:
DateTime lastOfDecember = new DateTime(firstOfDecember.Year, firstOfDecember.Month, lastDay);
使用DateTime
DaysInMonth
方法: DateTime.DaysInMonth方法(Int32,Int32)
在C#中,您可以使用DaysInMonth
DateTime endOfMonth = new DateTime (year, month,DateTime.DaysInMonth(year, month));
通过使用JQuery
var selectedData = txtfromdate;
var date = new Date(selectedData);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
所以,在lastDay变量中有结果。
通过使用C#
DateTime now = new Date(txtfromdate);
var startDate = new DateTime(now.Year, now.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
在endDate变量中有lastDate。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.