如何找到START DATE&所选月份的结束日期 [英] How to find START DATE & END DATE of Selected Month

查看:63
本文介绍了如何找到START DATE&所选月份的结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends,

        I have month & Year ( "March" & "2013" ) how can i find first date and last date of this month and Year. ( Like start date - 03/01/2013  & End date - 03/31/2013 )

推荐答案

可能的解决方案可能是

Possible solution could be
DateTime firstDay = new DateTime(2013, 3, 1);
DateTime lastDay = firstDay.AddMonths(1).AddDays(-1);



但是有一对夫妇:)



如果你想使用一个字符串


but there''s quite a couple :)

if you like to use a string

var firstDay = DateTime.Parse("1 March 2013");
var lastDay  = firstDay.AddMonths(1).AddDays(-1);


看看: DateTime Constructor( Int32,Int32,Int32) [ ^ ]和 DateTime.DaysInMonth方法 [ ^ ]



Heve a look at: DateTime Constructor (Int32, Int32, Int32)[^] and the DateTime.DaysInMonth Method[^]

DateTime start = new DateTime(2013,3,1);
DateTime end = new DateTime(2013,3,DateTime.DaysInMonth(2013,3));





祝你好运

Espen Harlinn



Best regards
Espen Harlinn


DateTime firstDateOfMonth = new DateTime(year, month, 1);
DateTime lastDateOfMonth = new DateTime(year, month, DateTime.DaysInMonth(year, month));


这篇关于如何找到START DATE&所选月份的结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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