Javascript Date Object from string in form 'HH-MM'

Hey, just wondering how to convert an HH:MM string into a javascript Date object. I have tried new Date(string); and myDate.setTime() but to no avail.

A side question could be: How to convert a string in HH:MM into milliseconds from Jan 1, 1970.

Thanks for your help in advance.

Answers


in JavaScript, I'm using the datejs library. http://www.datejs.com/ If you include this library, you have a function called "parseExact" and you could use it like this:

var dateString = "10-12";
var date = new Date.parseExact(dateString, "hh-mm");

To get the miliseconds, you can download the file time.js from http://code.google.com/p/datejs/source/browse/trunk/#trunk/src. Then you have a function getTotalMilliseconds() you can use:

var mSeconds = date.getTotalMilliseconds();

I hope this will help a little bit.


Need Your Help

C: Why can't I change the top binary tree node in a non-main method?

c binary-tree

I think this is more of a pointer problem than a binary tree problem. As an exercise I was re-creating a guessing/learning game in C using a binary tree. I had a method, traverse, which would go th...

Create a NSPredicate to find elements whose length is > N

iphone core-data

I have an array of strings ( more that 5k elements), each of variable length. I can use NSPredicate to find specific strings within the array( took a bit to figure that out). Now I need to find ele...

Are singleton classes thread-safe in IIS?

.net multithreading iis

I have an ASP.NET webpage running under IIS that uses a common assembly that contains a singleton class. Should I implement a locking mechanism on the singleton to make it thread-safe? Or, will any