Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: help

  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts

    help

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,935
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    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:
    Code:
    var now = new Date( );
    var localtime = now.toString();
    You can shortcut that to just:
    Code:
    var localtime = ( new Date( ) ).toString( );
    And if you want to know what it does, try this *complete HTML page*:
    Code:
    <html><body>
    <script type="text/javascript">
    document.write( ( new Date( ) ).toString( ) );
    </script>
    </body></html>
    if you have no other use for the now variable.
    Last edited by Old Pedant; 05-06-2009 at 03:14 AM.

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    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:
    Code:
    var now = new Date( );
    var localtime = now.toString();
    You can shortcut that to just:
    Code:
    var localtime = ( new Date( ) ).toString( );
    And if you want to know what it does, try this *complete HTML page*:
    Code:
    <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?

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    Quote Originally Posted by haydar View Post
    what is the .tostring doin? what isit used for? does it convert the variable to string?

    http://www.java2s.com/Code/JavaScrip...pt-Methods.htm

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

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by haydar View Post
    what is the .tostring doin? what isit used for? does it convert the variable to string?
    Code:
    <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.

  • #6
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Yeah, change the thread title to "Does .toString() convert something to a string?"
    That will make it less silly.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •