//默认当年1月1号 ViewBag.time1 = new DateTime(DateTime.Now.Year, 1, 1).ToString("yyyy-MM-dd"); ViewBag.time2 = DateTime.Now.ToString("yyyy-MM-dd");
new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy-MM-dd"); //获取当月第一天
string t = new DateTime(DateTime.Now.Year, 1, 1).ToString("yyyy-MM-dd"); //2019-01-01 string t1 = new DateTime(DateTime.Now.Year, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"); //2019-01-01 00:00:00
var 开始时间 = new DateTime(DateTime.Now.Year, 1, 1).ToString("yyyy-MM-dd"); //2019-01-01 var 结束时间 = new DateTime(DateTime.Now.Year, 12, 1).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd"); //2019-12-31
获取当天 时间
var time = Request.Form["time"].ToString().Trim(); DateTime min_time; // 比如时间字符串是 "2020-02-19" 转化为时间格式是 2020-02-19 00:00:00
var min_time = Convert.ToDateTime(time);
//上传的时间的当天最大时间是 var max_dtime = Convert.ToDateTime(min_time + "23:59:59");
-----
DateTime min_time111 = DateTime.Today; DateTime max_time111 = DateTime.Today.AddDays(1).AddSeconds(-1);