我从new Date(2012,9,3)
获得FormCollection["eventDate"]
如何在DateTime
变量中获取此值?
答案 0 :(得分:1)
string input = "new Date(2012,9,3)";
var dateTimeString = input.Split(new[] {'(', ')'},
StringSplitOptions.RemoveEmptyEntries)
.Last();
var datetime = DateTime.ParseExact(dateTimeString,
"yyyy,M,d", CultureInfo.InvariantCulture);
答案 1 :(得分:0)
一种方式是这样的:
// new Date(2012,9,3)
var dateVals = s.Substring(9).Replace(")", "").Split(",");
var d = new DateTime(
Convert.ToInt32(dateVals[0]),
Convert.ToInt32(dateVals[2]),
Convert.ToInt32(dateVals[1]));