Solved

Javascript Date

Posted on 2014-03-19
7
232 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now