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 3 of 3
Like Tree1Likes
  • 1 Post By Philip M

Thread: Learning Java, need an explanation

  1. #1
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Learning Java, need an explanation

    Hi there, first time posting here so I hope it's in the right area.
    I'm learning Javascript online, what I have to do is:

    Create a Date object for the end of the month in which you're doing this exercise.

    In a single statement display an alert that gives the number of days for that date since the reference date of January 1, 1970.

    Round it down to an integer.

    Click the Run It button to run your code live.


    My code:
    Code:
    var ex = new Date("March 31, 2014").getTime();
    alert(Math.floor(ex / (1000 * 60 * 60 * 24)));
    Why does .getTime() go in with the variable, and not in the alert?
    I'm aware of what it does, but not why it is placed up there. Help immensely appreciated

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    You could also express your code as

    Code:
    var ex = new Date("March 31, 2014");
    alert(Math.floor(ex.getTime() / (1000 * 60 * 60 * 24)));
    Be aware that Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    t3chn0ph1l3 likes this.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    t3chn0ph1l3 (03-30-2014)

  • #3
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the quick response and information!


  •  

    Posting Permissions

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