Solved

Javascript Date

Posted on 2014-03-19
7
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
arrays and radio buttons 10 46
Jquery Ajax - on change event not being picked up 9 57
isNaN issue on the Table input text 2 39
javascript duplicates 9 23
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

738 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