WildBill
WildBill

Reputation: 9291

How to parse date with date.js

I'm trying to do a simple parse/calculation with some times, but dateJS does not seem to be working. I have the date.js file loaded in the EXACT same directory as my HMTL file, but my error console is saying the Date object does not have the property of parse(). Am I missing something?

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.js"></script>
<script src="date.js"></script>
<script>
$(document).ready(function(){
 alert("hello");
 var future = new Date.parse("20:34:34");
 var now = new Date();
 var span = new TimeSpan(future - now);
 alert(span);
 alert("bye");
});
</script>
</head>
<body>

</body>
</html>

I corrected the code around parse but it still fails. My error console is now saying that TimeSpan is not defined...

And I pulled the datejs code off of their site TODAY. Though the repo says it was last updated in 2007...

Upvotes: 0

Views: 779

Answers (1)

Alexis Abril
Alexis Abril

Reputation: 6459

"parse" is a static method. You're using it as an instance method at the moment. Try changing:

Date().parse(..)

to

Date.parse(..)

Upvotes: 3

Related Questions