Solved

Javascript Date

Posted on 2014-03-19
7
241 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

691 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