Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6165891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:14:42+00:00 2026-05-23T22:14:42+00:00

I am new to JavaScript but need to run a check to make sure

  • 0

I am new to JavaScript but need to run a check to make sure it is daylight. I am using yahoo’s weather API to pull sunrise and sunset. I’m just a little confused as to the best approach for comparing its results to the current time.

I am confused because it returns a time like sunset: ‘9:01 pm’. bsince there is a PM it is text. I can’t think of a good way to compare it to the current time… RegExp, then convert to an integer maybe?

What would be the best approach to this, and why (sorry I’m trying to learn)?

Thanks in advance for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:14:43+00:00Added an answer on May 23, 2026 at 10:14 pm

    Create a new Date() with the info from yahoo’s api, then compare Date.now() with sunsetDate.getTime() and sunriseDate.getTime().

    Passing today’s date in mm/dd/yyyy format with the time as ‘9:01 pm’ to the Date constructor will give you a valid date.

    var today = new Date();
    today = [today.getMonth()+1, today.getDate(), today.getFullYear()].join('/');
    
    var yahooSunrise = '5:45 am';
    var yahooSunset = '9:01 pm';
    
    var sunrise = new Date(today + ' ' + yahooSunrise).getTime();
    var sunset = new Date(today + ' ' + yahooSunset).getTime();
    var now = Date.now();
    
    var isDaylight = (now > sunrise && now < sunset);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using PHP for too long, but I'm new to JavaScript integration in
New to javascript/jquery and having a hard time with using this or $(this) to
Is it possible to launch a new window in JavaScript using the window.Open function,
I've run into a problem where I make changes to a few JavaScript files
I'm having a JavaScript issue where I need a function to run and complete
I am loading Google API using google.load() and I need to process some of
I need to run a super long JavaScript on my page. The client is
I'm using webview in my xcode javascript refuses to run. has anyone got any
Using javascript, one of the things I need to do is when a button
I want to load a JavaScript file using Jint, but I can't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.