将C#语句转换为javascript [英] converting C# statements to javascript

查看:94
本文介绍了将C#语句转换为javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我想为以下语句编写JavaScript..

Dear All,

I want to write the javascript for the following statements..

DateTime DOB = Convert.ToDateTime(txtDOB.Text, format);
DateTime MatureDate = DOB.AddYears(18);
int temp = DateTime.Compare(MatureDate, System.DateTime.Now);




任何人都可以给我上面3条语句的javascript ...

问候,




Can any one please give me the javascript for the above 3 statements...

Regards,

推荐答案

我不会给您转换后的代码,但是让我来帮助您编写它.
第一句话,
DateTime DOB = Convert.ToDateTime(txtDOB.Text, format);
从文本框中获取值,然后使用JavaScript Date Object将其转换为日期.所以,
I won''t give you the converted code, but let me help you write it.
First statement,
DateTime DOB = Convert.ToDateTime(txtDOB.Text, format);
Get the value from the textbox and use JavaScript Date Object to convert it into date. So,
var txtDOB = document.getElementById('<%= txtDOB.ClientID %>').value;
var DOB = new Date(txtDOB);


在这里,我正在使用日期对象的此重载-new Date(dateString);
我将验证部分留给您.

第二句话,
DateTime MatureDate = DOB.AddYears(18);
JavaScript没有AddYears或类似功能.但是您可以在JavaScript中轻松添加年份.这是您的操作方法:


Here I am using the this overload of the date object - new Date(dateString);
I leave the validations part to you.

Second statement,
DateTime MatureDate = DOB.AddYears(18);
JavaScript doesn''t have a AddYears or similar function. But you can easily add years to a date in JavaScript. Here is how you do it:

var myDate = new Date();
myDate.setFullYear(myDate.getFullYear() + 18);


因此,您只需要为DOB做就可以了.即


So you just have to do it for DOB. i.e

DOB.setFullYear(DOB.getFullYear() + 18);



最后是第三行,
int temp = DateTime.Compare(MatureDate, System.DateTime.Now);

比较日期并不是一项艰巨的任务. JavaScript日期对象 [
希望这可以帮助! :thumbsup:



And finally the third line,
int temp = DateTime.Compare(MatureDate, System.DateTime.Now);

Comparing dates aren''t a big task. JavaScript Date Object[^]
Scroll down to the example "Compare Two Dates".

Hope this helps! :thumbsup:


这篇关于将C#语句转换为javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆