sometimes you just have to …

… calculate the number of seconds in the current year using JavaScript:

function seconds_in_this_year() {
      // get length of this year by subtracting "Jan 1st, /This Year/"
      // from  "Jan 1st, /Next Year/"
      var now = new Date();
      var current_year = now.getFullYear();
      var jan_first = new Date(current_year, 0, 1, 0, 0, 0, 0);
      var jan_next = new Date(current_year + 1, 0, 1, 0, 0, 0, 0);
      return (jan_next.getTime() - jan_first.getTime()) / 1000;
}

3 comments

  1. While you’re on the topic of esoterica, got any suggestions for someone who’s about to have to wade into Perl again after a multi-year absence?

    Sounds like my next task will involve writing some scripts, and I haven’t touched the camel for a good, oh, six years.

    “Touched the camel.” *shudders*

Leave a comment

Your email address will not be published. Required fields are marked *