本文介绍了查找日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

请帮助我,我在网上找不到.我需要查找一周中某天的日期,这意味着用户单击周日,然后周日的日期应显示在标签上.

在此先感谢

Hello friends,

Please help me I am unable to find on net. I need to find date of particular day in a week, which means user click on Sunday then date of Sunday should display on label.

thanks in advance

推荐答案

private DateTime GetDateBasedOnDay(string Pstrday)
		{
			DateTime LobjDate = null;

			DateTime LobjToday = DateTime.Now.Date;
			DayOfWeek LobjDayToday = LobjToday.DayOfWeek;

			DayOfWeek LobjLookUpDay = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), Pstrday);

			while (LobjToday.DayOfWeek != LobjLookUpDay)
			{
				LobjToday = LobjToday.AddDays(1);
			}

			LobjDate = LobjToday.Date;

			return LobjDate;

}


DayOfWeek week1 = DayOfWeek.Tuesday;
int dif = week1 - DateTime.Now.DayOfWeek;
if (dif < 0)
    dif += 7;

DateTime dt = DateTime.Now.AddDays(dif);
Console.WriteLine(dt);


这篇关于查找日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 13:12