Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  36] [ 7]  / answers: 1 / hits: 19404  / 13 Years ago, thu, march 15, 2012, 12:00:00

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


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.


This is the code line causing an issue:


var startTime = Date.parse($("#<%= StartTime.ClientID %>").val());  //code causing the issue


And StartTime is a textbox.


I am writing the above code in client/html in an ASP.NET application on the web form.


More From » jquery

 Answers
21

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.


[#86815] Wednesday, March 14, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janeth

Total Points: 498
Total Questions: 91
Total Answers: 89

Location: Malaysia
Member since Wed, May 11, 2022
2 Years ago
;