2 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊
使用DateTime.Parse或DateTime.ParseExact從字符串到日期時(shí)間的轉(zhuǎn)換更容易
所以,你可以試試這個(gè):
string?year?=?DateTime.Parse("2019-12-31").Year.ToString();

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊
我的問題是我在設(shè)置中拉取了 closeateyear 的空值。一旦我設(shè)置值 closedateyear = value; 工作后的一切:
private String closedateyear;
public String CloseDateYear
{
get { return closedateyear; }
set
{
closedateyear = value;
//retrieving data "2019-12-31"
DateTime date = Convert.ToDateTime(closedateyear);
//convert closedateyear to date time: similar to: "12/31/2019 12:00:00 AM"
int year = date.Year;
//extracting year: "2019"
closedateyear = year.ToString();
//set closedateyear = year value "12/31/2019 12:00:00 AM"
}
}
- 2 回答
- 0 關(guān)注
- 158 瀏覽
添加回答
舉報(bào)