...

View Full Version : help



haydar
05-06-2009, 02:44 AM
localtime =now.tostring()

what does this line do

not to sure what now.tostring() is...

would be the best if i get replies to this

thanks

Old Pedant
05-06-2009, 03:11 AM
No such thing as now

At least not built into JavaScript.

You have to *create* a variable of that name and initialize it for the code to make sense:


var now = new Date( );
var localtime = now.toString();

You can shortcut that to just:


var localtime = ( new Date( ) ).toString( );


And if you want to know what it does, try this *complete HTML page*:


<html><body>
<script type="text/javascript">
document.write( ( new Date( ) ).toString( ) );
</script>
</body></html>


if you have no other use for the now variable.

haydar
05-06-2009, 05:10 PM
No such thing as now

At least not built into JavaScript.

You have to *create* a variable of that name and initialize it for the code to make sense:


var now = new Date( );
var localtime = now.toString();

You can shortcut that to just:


var localtime = ( new Date( ) ).toString( );


And if you want to know what it does, try this *complete HTML page*:


<html><body>
<script type="text/javascript">
document.write( ( new Date( ) ).toString( ) );
</script>
</body></html>


if you have no other use for the now variable.


what is the .tostring doin? what isit used for? does it convert the variable to string?

TinyScript
05-06-2009, 05:43 PM
what is the .tostring doin? what isit used for? does it convert the variable to string?


http://www.java2s.com/Code/JavaScriptReference/Javascript-Methods/CatalogJavascript-Methods.htm

I'm still learning myself and this has been a huge help for me. I'm sure it will help you too.

Philip M
05-06-2009, 05:51 PM
what is the .tostring doin? what isit used for? does it convert the variable to string?


<script type = "text/javascript">
var now = new Date();
alert (typeof now + " " + now);
var localtime = now.toString();
alert (typeof localtime + " " + localtime);
</script>

Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose.

venegal
05-06-2009, 07:14 PM
Yeah, change the thread title to "Does .toString() convert something to a string?"
That will make it less silly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum