Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用mvc4中的当前日期计算年度日期_C#_Jquery_Mysql_Asp.net Mvc 4 - Fatal编程技术网

C# 使用mvc4中的当前日期计算年度日期

C# 使用mvc4中的当前日期计算年度日期,c#,jquery,mysql,asp.net-mvc-4,C#,Jquery,Mysql,Asp.net Mvc 4,我需要用mvc中的当前日期计算年度日期 让我们以今天的日期为例,我想在我的文本框中显示2017/3/24,用当前日期计算。。 是否有使用csharp或jquery计算日期的选项?C# 使用:- 编辑:-如果只需要日期零件 DateTime date = new DateTime(2016, 3, 24).Date; //OR DateTime date = DateTime.Now.Date; DateTime newDate = date.AddYears(1); .Date属性将DateT

我需要用mvc中的当前日期计算年度日期

让我们以今天的日期为例,我想在我的文本框中显示2017/3/24,用当前日期计算。。 是否有使用csharp或jquery计算日期的选项?

C#

使用:-

编辑:-如果只需要日期零件

DateTime date = new DateTime(2016, 3, 24).Date; //OR DateTime date = DateTime.Now.Date;
DateTime newDate = date.AddYears(1);
.Date
属性将DateTime对象的时间部分设置为
00:00:00
,如果要完全删除时间部分,则将日期转换为字符串作为
newDate.ToString(“MM/dd/yyyy”)

您可以在此MSDN中阅读有关自定义日期格式的更多信息

注意:-C#DateTime将始终具有时间部分(即使您使用
.Date
它将时间设置为
00:00:00
),如果您想完全删除时间,则必须将DateTime转换为字符串(如上所示)。

在Javascript中:

var fullDate = new Date(); var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1); var next_year = parseInt(fullDate.getFullYear())+1; var annualdate = next_year + "/" + twoDigitMonth + "/" + fullDate.getDate(); var fullDate=新日期(); var twoDigitMonth=((fullDate.getMonth().length+1)==1)?(fullDate.getMonth()+1):“0”+(fullDate.getMonth()+1); var next_year=parseInt(fullDate.getFullYear())+1; var annualdate=下一年+“/”+twoDigitMonth+“/”+fullDate.getDate();
可以编写Datetime date=new dateme(Datetime.Now)这样的代码吗????它显示了一个error@Souparnika..
DateTime.Now
本身将返回当前的DateTime对象我不认为传递
DateTime.Now
内部
DateTime
构造函数有任何意义…为什么要这样做?DateTime date=DateTime.Now.date如果只想使用当前DateTime,请使用
DateTime date=DateTime.Now
as我也提到了我的答案。好的,谢谢。。如果我只需要当前日期DateTime date=DateTime.Now.date DateTime newDate=date.AddYears(1);可能吗?@Kartikeya Khosla
DateTime日期=新的日期时间(2016年3月24日)。日期//或DateTime date=DateTime.Now.date;DateTime newDate=date.AddYears(1)它将显示时间ALSO@Karthikeya科斯拉这是可能的,但我想保存到数据库中,在这种情况下,这是不可能的!!
var fullDate = new Date();
    var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1);
    var next_year = parseInt(fullDate.getFullYear())+1;
    var annualdate = next_year + "/" + twoDigitMonth + "/" + fullDate.getDate();