Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a string 2

Status
Not open for further replies.

neillovell

Programmer
Aug 27, 2002
560
GB
Date() returns this

Wed Nov 20 11:36:47 UTC 2002

How can I parse it to give just the time?
 
You can try:

var now = new Date();
var timestring = "" + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds(); Never too old to learn...
Nico
 
nvb - you need to handle zeros (so you don't get 7:5:2 when it is 7:50:20)....


<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot;>

var now = new Date();
var timestring = &quot;&quot; + zero(now.getHours()) + &quot;:&quot; + zero(now.getMinutes()) + &quot;:&quot; + zero(now.getSeconds());

function zero(inNum){
inNum = &quot;&quot; + inNum //makes sure number is handles as string....
if(inNum.length == 1){
inNum = &quot;0&quot; + inNum
}
return inNum
}
alert (timestring)
</script> -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
Another way :
var date=new Date();
var strDate=new String(date.toLocaleTimeString());
alert (&quot;strDate = &quot; + strDate);
Water is not bad as long as it stays out human body ;-)
 
Much nicer than mine Targol (and easier) - Another star for you..... -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
thanx Mike Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top