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

org.hibernate.hql.internal.ast.QuerySyntaxException: EdbmsEmployee is not mapped

spring hibernate hibernate-mapping spring-orm

I am working on spring 3 hibernate 4 and new to ORM. so getting below Exception please help.

SqlDateTime Overflow must be between 1/1/1753 and 12/31/9999 coming from access to sql

c# sql ms-access console-application

I am taking data from an MS Access database and moving it to SQL Server using this code in my console application:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.