Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript Date

Posted on 2014-03-19
7
Medium Priority
?
245 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
Industry Leaders: 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 2000 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

Industry Leaders: 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

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…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

610 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