admin管理员组文章数量:1022670
i am looking to convert a date in string in javascript/jquery like '20/11/2013' to datetime for code behind like 2013-11-20 00:00:00.000 to be passed to the SQL.I cant add any extra jquery plugin to achieve this.
i am looking to convert a date in string in javascript/jquery like '20/11/2013' to datetime for code behind like 2013-11-20 00:00:00.000 to be passed to the SQL.I cant add any extra jquery plugin to achieve this.
Share Improve this question asked Nov 13, 2013 at 11:42 samsam 1052 silver badges9 bronze badges 3- do you really need to convert it clientside with javascript? Could you pass it to your C# and convert it there? – ED-209 Commented Nov 13, 2013 at 11:46
- You haven't to invent a bicycle ;) (w3schools./jsref/jsref_obj_date.asp) – user2604650 Commented Nov 13, 2013 at 11:48
- possible duplicate of Formatting a date in JavaScript – Frank van Puffelen Commented Nov 13, 2013 at 12:37
6 Answers
Reset to default 2Hi you can use with this.
new Date('2013-04-13');
or
new Date('2013-04-13T11:51:00');
var a = "2013-11-20 00:00:00.000";
var b = a.substring(0, a.indexOf(" ")).split('/');
alert (new Date(b))
You can do with two way
var a = "2013-11-20 00:00:00.000";
var b = a.substring(0, a.indexOf(" ")).split('-');
alert(new Date(b));
alert(new Date(b).toDateString());
First value returns long date second value returns sort date
try this in javascript
a = "20/11/2013";
var b = a.split('/');
alert( new Date(b[2],b[1],b[0]))
To get value from javascript you can use hidden field.
<script type="text/javascript">
function abc()
{
var str="datetime value";
document.getElementById("Hidden1").value=str;
}
</script>
<body>
<form id="form1" runat="server">
<div>
<input id="Hidden1" type="hidden" runat="server" />
<asp:Button ID="Button1" runat="server" OnClientClick="abc()" Text="Button"
onclick="Button1_Click" />
</div>
</form>
</body>
protected void Button1_Click(object sender, EventArgs e)
{
//Get the string
string datetime=Hidden1.Value
//Convert to datetime
//TODO
}
Try this.
DateTime Dt = DateTime.ParseExact(line[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
i am looking to convert a date in string in javascript/jquery like '20/11/2013' to datetime for code behind like 2013-11-20 00:00:00.000 to be passed to the SQL.I cant add any extra jquery plugin to achieve this.
i am looking to convert a date in string in javascript/jquery like '20/11/2013' to datetime for code behind like 2013-11-20 00:00:00.000 to be passed to the SQL.I cant add any extra jquery plugin to achieve this.
Share Improve this question asked Nov 13, 2013 at 11:42 samsam 1052 silver badges9 bronze badges 3- do you really need to convert it clientside with javascript? Could you pass it to your C# and convert it there? – ED-209 Commented Nov 13, 2013 at 11:46
- You haven't to invent a bicycle ;) (w3schools./jsref/jsref_obj_date.asp) – user2604650 Commented Nov 13, 2013 at 11:48
- possible duplicate of Formatting a date in JavaScript – Frank van Puffelen Commented Nov 13, 2013 at 12:37
6 Answers
Reset to default 2Hi you can use with this.
new Date('2013-04-13');
or
new Date('2013-04-13T11:51:00');
var a = "2013-11-20 00:00:00.000";
var b = a.substring(0, a.indexOf(" ")).split('/');
alert (new Date(b))
You can do with two way
var a = "2013-11-20 00:00:00.000";
var b = a.substring(0, a.indexOf(" ")).split('-');
alert(new Date(b));
alert(new Date(b).toDateString());
First value returns long date second value returns sort date
try this in javascript
a = "20/11/2013";
var b = a.split('/');
alert( new Date(b[2],b[1],b[0]))
To get value from javascript you can use hidden field.
<script type="text/javascript">
function abc()
{
var str="datetime value";
document.getElementById("Hidden1").value=str;
}
</script>
<body>
<form id="form1" runat="server">
<div>
<input id="Hidden1" type="hidden" runat="server" />
<asp:Button ID="Button1" runat="server" OnClientClick="abc()" Text="Button"
onclick="Button1_Click" />
</div>
</form>
</body>
protected void Button1_Click(object sender, EventArgs e)
{
//Get the string
string datetime=Hidden1.Value
//Convert to datetime
//TODO
}
Try this.
DateTime Dt = DateTime.ParseExact(line[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
本文标签: cConvert string to datetimejavascriptStack Overflow
版权声明:本文标题:c# - Convert string to datetime-javascript - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745473438a2152212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论