我想将像'20 / 11/2013'这样的javascript / jquery中的字符串中的日期转换为datetime,以便将诸如2013-11-20 00:00:00.000之类的代码传递给SQL。我无法添加任何额外的jquery插件来实现这一点。
Hi 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
}
尝试这个。
DateTime Dt = DateTime.ParseExact(line[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.