转换时间字符串说'12时05分“成JavaScript的使用Date.Parse日期时间 [英] convert a time string say '12:05 PM' into a datetime using Date.Parse in javascript
问题描述
我想时间字符串转换说'12时05分成JavaScript的使用Date.Parse日期时间。
当我传递的发言权12:05或12:10 PM或者...或者12:55 PM值低于startTime时返回的值是空,即 STARTTIME =空
I want to convert a time string say '12:05 PM' into a datetime using Date.Parse in javascript.
When I pass in a value of say 12:05 PM or 12:10 PM or ... or 12:55 PM the value returned by startTime below is null, i.e. startTime = null
但是当我通过在下午1:下午1时05分,下午1时10分,12:00 AM,...的价值观,下午12时00它工作正常结果
回到我包括时间日期。
But when I pass in values of 1:00 PM, 1:05 PM, 1:10 PM, 12:00 AM,...,12:00 PM it works fine
returning me a Date with the time included.
这是code线造成的一个问题:
This is the code line causing an issue:
var startTime = Date.parse($("#<%= StartTime.ClientID %>").val()); //code causing the issue
和为开始时间的文本框。
And StartTime is a textbox.
我写在客户机/ HTML上述code在Web表单上的ASP.NET应用程序。
I am writing the above code in client/html in an ASP.NET application on the web form.
推荐答案
如果你使用date.js然后尝试(按的测试案例这里)
If you're using date.js then try (as per test case here)
Date.parseExact("12:05 PM", "hh:mm tt");
这也应该拿起,如果你已经正确加载库。
This should also pick up if you've loaded the library correctly.
这篇关于转换时间字符串说'12时05分“成JavaScript的使用Date.Parse日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!