Solved

Javascript Date

Posted on 2014-03-19
7
237 Views
Last Modified: 2014-03-19
How can I convert this date 3/19/2014 12:00:00 to a javascript  new Date(2014,2,19,10,7,0) format, I know that the month starts at 0
0
Comment
Question by:smares323
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39940397
var str = "3/19/2014 12:00:00";
var arr = str.split(/\D/);
var d = new Date( arr[2], arr[0]*1-1, arr[1], arr[3], arr[4], arr[5] );

Open in new window

0
 

Author Comment

by:smares323
ID: 39940695
Not working it outputs Wed Mar 19 2014 12:00:00 GMT-0700 (Pacific Standard Time
0
 

Author Comment

by:smares323
ID: 39940697
I want to convert it to this forma new Date(2014,2,19,10,7,0)
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39940707
This "new Date(2014,2,19,10,7,0)" is a string
This new Date(2014,2,19,10,7,0) is a date

if you want the string :

var str = "3/19/2014 12:00:00";
var arr = str.split(/\D/);
str = "new Date(" +  arr[2] + "," + (arr[0]*1-1) + "," + arr[1] + "," + arr[3] + "," + arr[4] + "," + arr[5] + ")";

Open in new window

0
 

Author Comment

by:smares323
ID: 39940825
I'm passing this variable '3/19/2014 12:00:00' and need to put into this format new Date(2014,2,19,10,7,0) for javascript.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39940908
you already have the code for that but you certainly made an alert(d) to check and think you did not get it.
I give you both, the string and the required date
if you do an alert you will see your DATE in a STRING representation : Wed Mar 19 2014 12:00:00 GMT-0700
0
 

Author Closing Comment

by:smares323
ID: 39941022
great work
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question