2013-07-30 19 views
-3

如何將特定日期用作輸入值?調用特定的DateTime日期作爲輸入參數,c#

var experiment1 = WorkingWithDates.GetDisplayString("London", DateTime.Today, 45.00); 

後來,我將它轉換爲一個字符串,但我需要它作爲DateTime輸入。

public static string GetDisplayString(string city, DateTime date, double temp) 
{   
} 

我使用DateTime.Today作爲佔位符,只是因爲它的工作原理。事情是,我需要它作爲一年中一個月的特定日期的輸入。 (我試過使用(10,10,10),但它只是給我一個編譯器錯誤

編輯︰我不相信我沒有弄清楚我需要做的就是添加「新」感謝鄉親

+0

您的實例什麼「編譯器錯誤」 ?你究竟如何「嘗試使用(10,10,10)」? –

+0

您是否嘗試過使用'new DateTime'overloads,例如'new DateTime(2013,10,10)' – V4Vendetta

+0

您收到了哪些錯誤?另外,'10,10,10'代表10,10,或者我猜測,0010年,這不是你想要的。 – keyboardP

回答

0

(10, 10, 10)你想一年10

用作低於發生在一年,一個月,一天的構造。

DateTime dt = new DateTime(2013, 12, 12); 

然後打電話給你的方法

var experiment1 = WorkingWithDates.GetDisplayString("London", dt, 45.00); 

PS:如果你想每年10

DateTime dt = new DateTime(10, 10, 10); 

會工作。年將是0010

0
WorkingWithDates.GetDisplayString("London", DateTime.Today, 45.00); 

你需要一個DateTime對象代替DateTime.Today使用,因此構建使用

DateTime newdate = new DateTime(2013,10,10) // year, month , day 

然後

WorkingWithDates.GetDisplayString("London", newdate, 45.00); 
相關問題