473,394 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

split date time in javascript

250 100+
I want to split date and time in java script.ex: Date=2009-08-12 and Time=14:30:00
Expand|Select|Wrap|Line Numbers
  1. selectedDateTime = 2009-08-12 14:30:00
  2. date = selectedDateTime.split(" ") + "<br>";
  3.  
But I got the same value (2009-08-12 14:30:00). Could someone help me?
Aug 11 '09 #1
5 26657
Dormilich
8,658 Expert Mod 8TB
@ghjk
how do you print out the result?

EDIT: because you’re appending the <br> string the result array is converted and you end up where you begin. see String.split() @ MDC
Aug 11 '09 #2
ghjk
250 100+
solved.
Expand|Select|Wrap|Line Numbers
  1. selectedDateTime = "2009-08-12 14:30:00"
  2. var splitarray = new Array();
  3. splitarray= selectedDateTime.split(" ");
  4.  
Aug 13 '09 #3
Dormilich
8,658 Expert Mod 8TB
I don’t think you need line #2 (though it makes it obvious)
Aug 13 '09 #4
Expand|Select|Wrap|Line Numbers
  1. function datetime()
  2. {
  3. var selectedDateTime = "2009-08-12 14:30:00" 
  4. var splitarray = new Array(); 
  5. splitarray= selectedDateTime.split(" "); 
  6. document.write(splitarray[0]+"<br/>"+splitarray[1]);
  7. }
Aug 14 '09 #5
Dormilich
8,658 Expert Mod 8TB
@onlymukti4u
document.write() is not a very suitable method to make output. it will only work if you use inline script (which is not necessarily advantageous).
Aug 14 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Vince C. | last post by:
Hi all. I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've tried Response.Cookies("Test").Expires = Date(); Response.Cookies("Test").Expires =...
7
by: Harag | last post by:
Hi all I think this is in the wrong group but since I don't read others much or code in java script I was wondering if anyone could help me with this small problem, as I code mostly in ASP...
5
by: Gord | last post by:
Many scripts and calendars call client side system time in order to make presentations. However, the client's time may be improperly set, if set at all, and/or the relevant time may be from...
21
by: Javier | last post by:
Hi I´ve a routine that will read date and times in a vector of strings ie: 30/02/2005 19:20 In some moment I´ll need to check if there are in vector a date like current date with a time...
2
by: Richard | last post by:
I have a textbox and an HtmlInputButton control on a Webform for an Intranet app. When the user clicks the button, it is supposed to add today's date to the textbox using JavaScript on the client...
8
by: David | last post by:
I'm trying to add a date and time to an html form, but I'm having a bit of trouble getting it working. Any suggestions? Thanks! ~ David (merlin001_at_gmail_dot_com)
3
by: brendanmcdonagh | last post by:
I have these values in an array after using split $alltogether = $day . "," . $month . "," . $hour . "," . $minutes . ","; $arr=split(",",$alltogether); // splitting the array $d=$arr; //...
0
by: Syed Khaleel Ahamed | last post by:
Dear Sir, I want to get the difference of date/time captured in mysql and present date/time in jsp. I am using the following code to get, but its getting difference only in hrs, i used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.