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

  • SEARCH
  • Home
  • 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

New to javascript, but I'm sure this is easy. Unfortunately, most of the google
I am using http://nithinbekal.com/2009/javascript-how-to-create-a-simple-countdown-timer/ But when I run it in firefox I get the
I'm quite new to javascript but have undertaken a task to get better aquainted
im new at javascript and i can get this slider to work but not
I'm new to javascript/jquery and I've done some poking around the web, but I
I'm so close to figuring this out, i think. I'm new to javascript, but
I'm completely new to the javascript and ajax world but trying to learn. Right
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.
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

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.