Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return only time #52

Closed
idriskhenchil opened this issue May 2, 2021 · 1 comment
Closed

Return only time #52

idriskhenchil opened this issue May 2, 2021 · 1 comment

Comments

@idriskhenchil
Copy link

Is it possible to return only the hours and minutes of the sunset or sunrise?

@cliftonlabrum
Copy link

You can just use a Date extension to accomplish this.

extension Date
  var time: String{
    let formatter = DateFormatter()
    formatter.dateFormat = "H:mm" //Whatever time format you want
    return formatter.string(from: self)
  }
}

Then when you use Solar, just convert it like this:

let solar = Solar(coordinate: CLLocationCoordinate2D(latitude: latitude, longitude: longitude))
let sunrise = solar?.sunrise
let sunset = solar?.sunset

print("Sunrise: \(sunrise?.time)")
print("Sunset: \(sunset?.time)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants