質問

C# で、指定された緯度と経度から、指定された日の太陽の沈み時間と昇り時間を計算する方法はありますか?

役に立ちましたか?

解決

Javascriptの計算<デル> ここ。今、あなただけのポートにする必要があります。

<時間>

編集:計算は今このページのソースコードでありますます。

<時間>

編集:ここのソースへの直接リンクですコード。 HTMLを通じて狩りへ行く必要はありませんん。

他のヒント

私はこの記事が古いですけど、場合には、誰もが、まだ探しています...

CoordinateSharp のNugetパッケージとして提供されています。これは、太陽や月の時間を扱うことができるスタンドアロンpackgeです。

Celestial cel = Celestial.CalculateCelestialTimes(85.57682, -70.75678, new DateTime(2017,8,21));
Console.WriteLine(cel.SunRise.Value.ToString());

注:

これは、日付時刻がUTCに常にあると仮定します。

最後に、あなたは日付がnullを返した場合日/月の.Condition天体を参照する必要があります。太陽がアップ/ダウンのすべての日である場合に発生します。

EDIT 2019年1月9日

ライブラリーは、この記事以来、劇的に変化しました。それは今だけでなく地元の回を扱うことができます。

私はC#で、このライブラリーを作成するために、NAAはJavaScriptとC#を使用します。

日の出と日没のC#する

私はこれら二つのサイトに対してそれをテストし、それはサイトが行うまったく同じ時間を示しています。

http://www.timeanddate.com/sun/usa/seattle

http://www.esrl.noaa.gov/gmd/grad/solcalc/する

このAPIは、私のために動作するようです。

http://sunrise-sunset.org/apiする

これに対する受け入れられた答えは JavaScript の実装でしたが、C# で計算を行う必要があったため、私のアプリケーションには適していませんでした。

この C# コードを使用しました。 http://wiki.crowe.co.nz/Calculate%20Sunrise%2fSunset.ashx, 、ここで日の出/日の入りの時刻に対して検証しました。 http://www.timeanddate.com/astronomy/.

秒を最も近い分に四捨五入すると、C# 実装の日の出時刻と日の入り時刻は、夏時間の場合も含め、timeanddate.com に表示される対応する値と一致します。ただし、このコードは少し複雑です (月齢データも必要でない限り)。数値が正しくなったので、具体的に必要なことを行うためにコードをリファクタリングします。

この情報を起動します:

Sunrise_equationする

私はライトすることにまだあるRubyスクリプトを、これを使用しています。 私はトラブルマルチパートユリウス日付を理解を持っています。

は明らかであることの一つは、あなたが正確な太陽通過時間のために行くべきであるということです。 次いで基づくsemi_diurnal_arc = ACOS(cos_omega)を減算し、追加 あなたの緯度と太陽赤緯時に。ああ!そして、太陽を含めるようにしてください センターと地球屈折。この地球はかなり魔術師であるようです。

また、自動的にタイムゾーンを決定することができdotsaの答え、の

VB.Netバージョンます。

(この夜夕日を見てチェックする)出力:

Main.VBます:

Module Main

Sub Main()

    ' http://www.timeanddate.com/sun/usa/seattle
    ' http://www.esrl.noaa.gov/gmd/grad/solcalc/

    ' Vessy, Switzerland
    Dim latitude As Double = 46.17062
    Dim longitude As Double = 6.161667
    Dim dst As Boolean = True
    Dim timehere As DateTime = DateTime.Now

    Console.WriteLine("It is currently {0:HH:mm:ss} UTC", DateTime.UtcNow)
    Console.WriteLine("The time here, at {0}°,{1}° is {2:HH:mm:ss}", latitude, longitude, timehere)
    Dim local As TimeZoneInfo = TimeZoneInfo.Local
    Dim zone As Integer = local.BaseUtcOffset().TotalHours

    If local.SupportsDaylightSavingTime Then
        Dim standard As String = local.StandardName
        Dim daylight As String = local.DaylightName
        dst = local.IsDaylightSavingTime(timehere)
        Dim current As String = IIf(dst, daylight, standard)
        Console.WriteLine("Daylight-saving time is supported here. Current offset {0:+0} hours, {1}", zone, current)
    Else
        Console.WriteLine("Daylight-saving time is not supported here")
    End If

    System.Console.WriteLine("Sunrise today {0}", Sunrises(latitude, longitude))
    System.Console.WriteLine("Sunset  today {0}", Sunsets(latitude, longitude))
    System.Console.ReadLine()
End Sub

End Module

Sun.vbます:

Public Module Sun
' Get sunrise time at latitude, longitude using local system timezone
Function Sunrises(latitude As Double, longitude As Double) As DateTime
    Dim julian As Double = JulianDay(DateTime.Now)
    Dim rises As Double = SunRiseUTC(julian, latitude, longitude)
    Dim timehere As DateTime = DateTime.Now
    Dim local As TimeZoneInfo = TimeZoneInfo.Local
    Dim dst As Boolean = local.IsDaylightSavingTime(timehere)
    Dim zone As Integer = local.BaseUtcOffset().TotalHours
    Dim result As DateTime = getDateTime(rises, zone, timehere, dst)
    Return result
End Function
' Get sunset time at latitude, longitude using local system timezone
Function Sunsets(latitude As Double, longitude As Double) As DateTime
    Dim julian As Double = JulianDay(DateTime.Now)
    Dim rises As Double = SunSetUTC(julian, latitude, longitude)
    Dim timehere As DateTime = DateTime.Now
    Dim local As TimeZoneInfo = TimeZoneInfo.Local
    Dim dst As Boolean = local.IsDaylightSavingTime(timehere)
    Dim zone As Integer = local.BaseUtcOffset().TotalHours
    Dim result As DateTime = getDateTime(rises, zone, timehere, dst)
    Return result
End Function
' Convert radian angle to degrees
Public Function Degrees(angleRad As Double) As Double
    Return (180.0 * angleRad / Math.PI)
End Function
' Convert degree angle to radians
Public Function Radians(angleDeg As Double) As Double
    Return (Math.PI * angleDeg / 180.0)
End Function
'* Name: JulianDay  
'* Type: Function   
'* Purpose: Julian day from calendar day    
'* Arguments:   
'* year : 4 digit year  
'* month: January = 1   
'* day : 1 - 31 
'* Return value:    
'* The Julian day corresponding to the date 
'* Note:    
'* Number is returned for start of day. Fractional days should be   
'* added later. 
Public Function JulianDay(year As Integer, month As Integer, day As Integer) As Double
    If month <= 2 Then
        year -= 1
        month += 12
    End If
    Dim A As Double = Math.Floor(year / 100.0)
    Dim B As Double = 2 - A + Math.Floor(A / 4)

    Dim julian As Double = Math.Floor(365.25 * (year + 4716)) + Math.Floor(30.6001 * (month + 1)) + day + B - 1524.5
    Return julian
End Function

Public Function JulianDay([date] As DateTime) As Double
    Return JulianDay([date].Year, [date].Month, [date].Day)
End Function

'***********************************************************************/
'* Name: JulianCenturies    
'* Type: Function   
'* Purpose: convert Julian Day to centuries since J2000.0.  
'* Arguments:   
'* julian : the Julian Day to convert   
'* Return value:    
'* the T value corresponding to the Julian Day  
'***********************************************************************/

Public Function JulianCenturies(julian As Double) As Double
    Dim T As Double = (julian - 2451545.0) / 36525.0
    Return T
End Function


'***********************************************************************/
'* Name: JulianDayFromJulianCentury 
'* Type: Function   
'* Purpose: convert centuries since J2000.0 to Julian Day.  
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* the Julian Day corresponding to the t value  
'***********************************************************************/

Public Function JulianDayFromJulianCentury(t As Double) As Double
    Dim julian As Double = t * 36525.0 + 2451545.0
    Return julian
End Function


'***********************************************************************/
'* Name: calGeomMeanLongSun 
'* Type: Function   
'* Purpose: calculate the Geometric Mean Longitude of the Sun   
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* the Geometric Mean Longitude of the Sun in degrees   
'***********************************************************************/

Public Function GemoetricMeanLongitude(t As Double) As Double
    Dim L0 As Double = 280.46646 + t * (36000.76983 + 0.0003032 * t)
    While L0 > 360.0
        L0 -= 360.0
    End While
    While L0 < 0.0
        L0 += 360.0
    End While
    Return L0
    ' in degrees
End Function


'***********************************************************************/
'* Name: calGeomAnomalySun  
'* Type: Function   
'* Purpose: calculate the Geometric Mean Anomaly of the Sun 
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* the Geometric Mean Anomaly of the Sun in degrees 
'***********************************************************************/

Public Function GemoetricMeanAnomaly(t As Double) As Double
    Dim M As Double = 357.52911 + t * (35999.05029 - 0.0001537 * t)
    Return M
    ' in degrees
End Function

'***********************************************************************/
'* Name: EarthOrbitEccentricity 
'* Type: Function   
'* Purpose: calculate the eccentricity of earth's orbit 
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* the unitless eccentricity    
'***********************************************************************/


Public Function EarthOrbitEccentricity(t As Double) As Double
    Dim e As Double = 0.016708634 - t * (0.000042037 + 0.0000001267 * t)
    Return e
    ' unitless
End Function

'***********************************************************************/
'* Name: SunCentre  
'* Type: Function   
'* Purpose: calculate the equation of center for the sun    
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* in degrees   
'***********************************************************************/


Public Function SunCentre(t As Double) As Double
    Dim m As Double = GemoetricMeanAnomaly(t)

    Dim mrad As Double = Radians(m)
    Dim sinm As Double = Math.Sin(mrad)
    Dim sin2m As Double = Math.Sin(mrad + mrad)
    Dim sin3m As Double = Math.Sin(mrad + mrad + mrad)

    Dim C As Double = sinm * (1.914602 - t * (0.004817 + 0.000014 * t)) + sin2m * (0.019993 - 0.000101 * t) + sin3m * 0.000289
    Return C
    ' in degrees
End Function

'***********************************************************************/
'* Name: SunTrueLongitude   
'* Type: Function   
'* Purpose: calculate the true longitude of the sun 
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* sun's true longitude in degrees  
'***********************************************************************/


Public Function SunTrueLongitude(t As Double) As Double
    Dim l0 As Double = GemoetricMeanLongitude(t)
    Dim c As Double = SunCentre(t)

    Dim O As Double = l0 + c
    Return O
    ' in degrees
End Function

'***********************************************************************/
'* Name: SunTrueAnomaly 
'* Type: Function   
'* Purpose: calculate the true anamoly of the sun   
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* sun's true anamoly in degrees    
'***********************************************************************/

Public Function SunTrueAnomaly(t As Double) As Double
    Dim m As Double = GemoetricMeanAnomaly(t)
    Dim c As Double = SunCentre(t)

    Dim v As Double = m + c
    Return v
    ' in degrees
End Function

'***********************************************************************/
'* Name: SunDistanceAU  
'* Type: Function   
'* Purpose: calculate the distance to the sun in AU 
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* sun radius vector in AUs 
'***********************************************************************/

Public Function SunDistanceAU(t As Double) As Double
    Dim v As Double = SunTrueAnomaly(t)
    Dim e As Double = EarthOrbitEccentricity(t)

    Dim R As Double = (1.000001018 * (1 - e * e)) / (1 + e * Math.Cos(Radians(v)))
    Return R
    ' in AUs
End Function

'***********************************************************************/
'* Name: SunApparentLongitude   
'* Type: Function   
'* Purpose: calculate the apparent longitude of the sun 
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* sun's apparent longitude in degrees  
'***********************************************************************/

Public Function SunApparentLongitude(t As Double) As Double
    Dim o As Double = SunTrueLongitude(t)

    Dim omega As Double = 125.04 - 1934.136 * t
    Dim lambda As Double = o - 0.00569 - 0.00478 * Math.Sin(Radians(omega))
    Return lambda
    ' in degrees
End Function

'***********************************************************************/
'* Name: MeanObliquityOfEcliptic    
'* Type: Function   
'* Purpose: calculate the mean obliquity of the ecliptic    
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* mean obliquity in degrees    
'***********************************************************************/

Public Function MeanObliquityOfEcliptic(t As Double) As Double
    Dim seconds As Double = 21.448 - t * (46.815 + t * (0.00059 - t * (0.001813)))
    Dim e0 As Double = 23.0 + (26.0 + (seconds / 60.0)) / 60.0
    Return e0
    ' in degrees
End Function

'***********************************************************************/
'* Name: calcObliquityCorrection    
'* Type: Function   
'* Purpose: calculate the corrected obliquity of the ecliptic   
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* corrected obliquity in degrees   
'***********************************************************************/

Public Function calcObliquityCorrection(t As Double) As Double
    Dim e0 As Double = MeanObliquityOfEcliptic(t)

    Dim omega As Double = 125.04 - 1934.136 * t
    Dim e As Double = e0 + 0.00256 * Math.Cos(Radians(omega))
    Return e
    ' in degrees
End Function

'***********************************************************************/
'* Name: SunRightAscension  
'* Type: Function   
'* Purpose: calculate the right ascension of the sun    
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* sun's right ascension in degrees 
'***********************************************************************/

Public Function SunRightAscension(t As Double) As Double
    Dim e As Double = calcObliquityCorrection(t)
    Dim lambda As Double = SunApparentLongitude(t)

    Dim tananum As Double = (Math.Cos(Radians(e)) * Math.Sin(Radians(lambda)))
    Dim tanadenom As Double = (Math.Cos(Radians(lambda)))
    Dim alpha As Double = Degrees(Math.Atan2(tananum, tanadenom))
    Return alpha
    ' in degrees
End Function

'***********************************************************************/
'* Name: SunDeclination 
'* Type: Function   
'* Purpose: calculate the declination of the sun    
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* sun's declination in degrees 
'***********************************************************************/

Public Function SunDeclination(t As Double) As Double
    Dim e As Double = calcObliquityCorrection(t)
    Dim lambda As Double = SunApparentLongitude(t)

    Dim sint As Double = Math.Sin(Radians(e)) * Math.Sin(Radians(lambda))
    Dim theta As Double = Degrees(Math.Asin(sint))
    Return theta
    ' in degrees
End Function

'***********************************************************************/
'* Name: TrueSolarToMeanSolar   
'* Type: Function   
'* Purpose: calculate the difference between true solar time and mean   
'*   solar time 
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* Return value:    
'* equation of time in minutes of time  
'***********************************************************************/

Public Function TrueSolarToMeanSolar(t As Double) As Double
    Dim epsilon As Double = calcObliquityCorrection(t)
    Dim l0 As Double = GemoetricMeanLongitude(t)
    Dim e As Double = EarthOrbitEccentricity(t)
    Dim m As Double = GemoetricMeanAnomaly(t)

    Dim y As Double = Math.Tan(Radians(epsilon) / 2.0)
    y *= y

    Dim sin2l0 As Double = Math.Sin(2.0 * Radians(l0))
    Dim sinm As Double = Math.Sin(Radians(m))
    Dim cos2l0 As Double = Math.Cos(2.0 * Radians(l0))
    Dim sin4l0 As Double = Math.Sin(4.0 * Radians(l0))
    Dim sin2m As Double = Math.Sin(2.0 * Radians(m))

    Dim Etime As Double = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - 0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m

    Return Degrees(Etime) * 4.0
    ' in minutes of time
End Function

'***********************************************************************/
'* Name: SunriseHourAngle   
'* Type: Function   
'* Purpose: calculate the hour angle of the sun at sunrise for the  
'*   latitude   
'* Arguments:   
'* lat : latitude of observer in degrees    
'*  solarDec : declination angle of sun in degrees  
'* Return value:    
'* hour angle of sunrise in radians 
'***********************************************************************/

Public Function SunriseHourAngle(lat As Double, solarDec As Double) As Double
    Dim latRad As Double = Radians(lat)
    Dim sdRad As Double = Radians(solarDec)

    Dim HAarg As Double = (Math.Cos(Radians(90.833)) / (Math.Cos(latRad) * Math.Cos(sdRad)) - Math.Tan(latRad) * Math.Tan(sdRad))

    Dim HA As Double = (Math.Acos(Math.Cos(Radians(90.833)) / (Math.Cos(latRad) * Math.Cos(sdRad)) - Math.Tan(latRad) * Math.Tan(sdRad)))

    Return HA
    ' in radians
End Function

'***********************************************************************/
'* Name: SunsetHourAngle    
'* Type: Function   
'* Purpose: calculate the hour angle of the sun at sunset for the   
'*   latitude   
'* Arguments:   
'* lat : latitude of observer in degrees    
'*  solarDec : declination angle of sun in degrees  
'* Return value:    
'* hour angle of sunset in radians  
'***********************************************************************/

Public Function SunsetHourAngle(lat As Double, solarDec As Double) As Double
    Dim latRad As Double = Radians(lat)
    Dim sdRad As Double = Radians(solarDec)

    Dim HAarg As Double = (Math.Cos(Radians(90.833)) / (Math.Cos(latRad) * Math.Cos(sdRad)) - Math.Tan(latRad) * Math.Tan(sdRad))

    Dim HA As Double = (Math.Acos(Math.Cos(Radians(90.833)) / (Math.Cos(latRad) * Math.Cos(sdRad)) - Math.Tan(latRad) * Math.Tan(sdRad)))

    Return -HA
    ' in radians
End Function


'***********************************************************************/
'* Name: SunRiseUTC 
'* Type: Function   
'* Purpose: calculate the Universal Coordinated Time (UTC) of sunrise   
'*   for the given day at the given location on earth   
'* Arguments:   
'* julian : julian day  
'* latitude : latitude of observer in degrees   
'* longitude : longitude of observer in degrees 
'* Return value:    
'* time in minutes from zero Z  
'***********************************************************************/

'Public  Function SunRiseUTC(julian As Double, latitude As Double, longitude As Double) As Double
'    Dim t As Double = JulianCenturies(julian)

'    ' *** Find the time of solar noon at the location, and use
'    ' that declination. This is better than start of the 
'    ' Julian day

'    Dim noonmin As Double = SolarNoonUTC(t, longitude)
'    Dim tnoon As Double = JulianCenturies(julian + noonmin / 1440.0)

'    ' *** First pass to approximate sunrise (using solar noon)

'    Dim eqTime As Double = TrueSolarToMeanSolar(tnoon)
'    Dim solarDec As Double = SunDeclination(tnoon)
'    Dim hourAngle As Double = SunriseHourAngle(latitude, solarDec)

'    Dim delta As Double = longitude - Degrees(hourAngle)
'    Dim timeDiff As Double = 4 * delta
'    ' in minutes of time
'    Dim timeUTC As Double = 720 + timeDiff - eqTime
'    ' in minutes
'    ' alert("eqTime = " + eqTime + "\nsolarDec = " + solarDec + "\ntimeUTC = " + timeUTC);

'    ' *** Second pass includes fractional julianay in gamma calc

'    Dim newt As Double = JulianCenturies(JulianDayFromJulianCentury(t) + timeUTC / 1440.0)
'    eqTime = TrueSolarToMeanSolar(newt)
'    solarDec = SunDeclination(newt)
'    hourAngle = SunriseHourAngle(latitude, solarDec)
'    delta = longitude - Degrees(hourAngle)
'    timeDiff = 4 * delta
'    timeUTC = 720 + timeDiff - eqTime
'    ' in minutes
'    ' alert("eqTime = " + eqTime + "\nsolarDec = " + solarDec + "\ntimeUTC = " + timeUTC);

'    Return timeUTC
'End Function

'***********************************************************************/
'* Name: SolarNoonUTC   
'* Type: Function   
'* Purpose: calculate the Universal Coordinated Time (UTC) of solar 
'*   noon for the given day at the given location on earth  
'* Arguments:   
'* t : number of Julian centuries since J2000.0 
'* longitude : longitude of observer in degrees 
'* Return value:    
'* time in minutes from zero Z  
'***********************************************************************/

Public Function SolarNoonUTC(t As Double, longitude As Double) As Double
    ' First pass uses approximate solar noon to calculate eqtime
    Dim tnoon As Double = JulianCenturies(JulianDayFromJulianCentury(t) + longitude / 360.0)
    Dim eqTime As Double = TrueSolarToMeanSolar(tnoon)
    Dim solNoonUTC As Double = 720 + (longitude * 4) - eqTime
    ' min
    Dim newt As Double = JulianCenturies(JulianDayFromJulianCentury(t) - 0.5 + solNoonUTC / 1440.0)

    eqTime = TrueSolarToMeanSolar(newt)
    ' double solarNoonDec = SunDeclination(newt);
    solNoonUTC = 720 + (longitude * 4) - eqTime
    ' min
    Return solNoonUTC
End Function

'***********************************************************************/
'* Name: SunSetUTC  
'* Type: Function   
'* Purpose: calculate the Universal Coordinated Time (UTC) of sunset    
'*   for the given day at the given location on earth   
'* Arguments:   
'* julian : julian day  
'* latitude : latitude of observer in degrees   
'* longitude : longitude of observer in degrees 
'* Return value:    
'* time in minutes from zero Z  
'***********************************************************************/

Public Function SunSetUTC(julian As Double, latitude As Double, longitude As Double) As Double
    Dim t = JulianCenturies(julian)
    Dim eqTime = TrueSolarToMeanSolar(t)
    Dim solarDec = SunDeclination(t)
    Dim hourAngle = SunriseHourAngle(latitude, solarDec)
    hourAngle = -hourAngle
    Dim delta = longitude + Degrees(hourAngle)
    Dim timeUTC = 720 - (4.0 * delta) - eqTime
    ' in minutes
    Return timeUTC
End Function

Public Function SunRiseUTC(julian As Double, latitude As Double, longitude As Double) As Double
    Dim t = JulianCenturies(julian)
    Dim eqTime = TrueSolarToMeanSolar(t)
    Dim solarDec = SunDeclination(t)
    Dim hourAngle = SunriseHourAngle(latitude, solarDec)
    Dim delta = longitude + Degrees(hourAngle)
    Dim timeUTC = 720 - (4.0 * delta) - eqTime
    ' in minutes
    Return timeUTC
End Function

Public Function getTimeString(time As Double, timezone As Integer, julian As Double, dst As Boolean) As String
    Dim timeLocal = time + (timezone * 60.0)
    Dim riseT = JulianCenturies(julian + time / 1440.0)
    timeLocal += (If((dst), 60.0, 0.0))
    Return getTimeString(timeLocal)
End Function

Public Function getDateTime(time As Double, timezone As Integer, [date] As DateTime, dst As Boolean) As System.Nullable(Of DateTime)
    Dim julian As Double = JulianDay([date])
    Dim timeLocal = time + (timezone * 60.0)
    Dim riseT = JulianCenturies(julian + time / 1440.0)
    timeLocal += (If((dst), 60.0, 0.0))
    Return getDateTime(timeLocal, [date])
End Function

Private Function getTimeString(minutes As Double) As String

    Dim output As String = ""

    If (minutes >= 0) AndAlso (minutes < 1440) Then
        Dim floatHour = minutes / 60.0
        Dim hour = Math.Floor(floatHour)
        Dim floatMinute = 60.0 * (floatHour - Math.Floor(floatHour))
        Dim minute = Math.Floor(floatMinute)
        Dim floatSec = 60.0 * (floatMinute - Math.Floor(floatMinute))
        Dim second = Math.Floor(floatSec + 0.5)
        If second > 59 Then
            second = 0
            minute += 1
        End If
        If (second >= 30) Then
            minute += 1
        End If
        If minute > 59 Then
            minute = 0
            hour += 1
        End If
        output = [String].Format("{0:00}:{1:00}", hour, minute)
    Else
        Return "error"
    End If

    Return output
End Function

Private Function getDateTime(minutes As Double, [date] As DateTime) As System.Nullable(Of DateTime)

    Dim retVal As System.Nullable(Of DateTime) = Nothing

    If (minutes >= 0) AndAlso (minutes < 1440) Then
        Dim floatHour = minutes / 60.0
        Dim hour = Math.Floor(floatHour)
        Dim floatMinute = 60.0 * (floatHour - Math.Floor(floatHour))
        Dim minute = Math.Floor(floatMinute)
        Dim floatSec = 60.0 * (floatMinute - Math.Floor(floatMinute))
        Dim second = Math.Floor(floatSec + 0.5)
        If second > 59 Then
            second = 0
            minute += 1
        End If
        If (second >= 30) Then
            minute += 1
        End If
        If minute > 59 Then
            minute = 0
            hour += 1
        End If
        Return New DateTime([date].Year, [date].Month, [date].Day, CInt(hour), CInt(minute), CInt(second))
    Else
        Return retVal
    End If
End Function
End Module

私はそれを行うための簡単なPythonスクリプトを作りました: SunriseSunsetCalculatorする

私は、クラス内でそれをラップするためには至っていないが、それは他の人のために有用である可能性がある。

<時間>

編集:オープンソースは、基本的なスクリプトを犯しているので、素晴らしいです、誰かがモジュールでそれを包み、もう一つは、CLIインタフェースを追加しました!おかげmbideauと彼らの貢献のためにnfischerする!

あなたは太陽の周りを地球ムーンシステムの偏心軌道を可能にするための時間の方程式を含んで式を必要としています。あなたは、このようなWGS84またはNAD27またはそのような何かのように、適切な基準点と座標を使用する必要があります。あなたはユリウス暦ではなく、我々は右のこれらの時間をget5するために日常的に使用するものを使用する必要があります。時間の秒以内に推測することは容易なことではありません。 ID影の長さは、どんな高さに等しい私の場所での時間を持ちたいです。日が高く正午前後に60度の地平線上に上昇したとき、これは1日2回起こるはず。また、私の知る限り理解し、あなたはちょうどあなたがあなたのクロック周波数X 366.25 / 365.25を増やす好きなら、あなたは今、代わりに民事クロックの恒星クロックを持っているかもしれないので、恒星時を取得するために、毎年、正確に一日を追加する必要があります? 「MATHは、強力な誰かが宇宙を書かれている言語である」

もう一つの良いJSの実装では、 suncalc のです。

のコード行数が管理され、従って(C#の)他の言語に移植することは確かに可能である。

外部サービスを使用したい場合は、この素晴らしい無料の日の出と日の入りの時間 API を使用できます。 http://sunrise-sunset.org/api

私はいくつかのプロジェクトでそれを使用していますが、非常にうまく機能し、データは非常に正確であるようです。HTTP GET リクエストを実行するだけです http://api.sunrise-sunset.org/json

受け入れられるパラメータ:

  • 緯度:緯度を 10 進数で表します。必須。
  • 長さ:経度を 10 進数で表します。必須。
  • 日付:YYYY-MM-DD 形式の日付。他の日付形式や相対日付形式も受け入れます。存在しない場合、日付はデフォルトで現在の日付になります。オプション。
  • 折り返し電話:JSONP 応答のコールバック関数名。オプション。
  • フォーマット済み:0 または 1 (1 がデフォルト)。応答の時間値は ISO 8601 に従って表現され、day_length は秒単位で表現されます。オプション。

応答には、日の出と日の入りの時刻、および夕暮れの時刻が含まれます。

私はUWPにこのnugetパッケージをテストしています。

https://www.nuget.org/packages/SolarCalculator/する

ドキュメントは少し大ざっぱであり、ここではあります:

https://github.com/porrey/Solar-Calculatorする

あなたは日の出を取得するためにこれを使用することができ、与えられた

ラ=緯度。そしてLOは経度を=。お住まいの地域のために:

            SolarTimes solarTimes = new SolarTimes(DateTime.Now, la, lo);
            DateTime sr = solarTimes.Sunrise;
            DateTime dt = Convert.ToDateTime(sr);
            textblockb.Text = dt.ToString("h:mm:ss");

あなたはPMマネージャを使用してVisual Studioでそれをインストールすることができます。

Install-Package SolarCalculator -Version 2.0.2 

または "NuGetパッケージの管理" のVisual StudioライブラリにSolarCalculatorを調べてます。

はい、いくつかを終了します。

パターンのためのいくつかのリンクます。

http://williams.best.vwh.net/sunrise_sunset_example.htmする

のhttp:// WWW。 codeproject.com/Articles/29306/C-Class-for-Calculating-Sunrise-and-Sunset-Timesする

<のhref = "https://social.msdn.microsoft.com/Forums/vstudio/en-US/a4fad4c3-6d18-41fc-82b7-1f3031349837/get-sunrise-and-sunset-time-based-オン緯度経度?フォーラム= csharpgeneral」REL = 『nofollowを』> https://social.msdn.microsoft.com/Forums/vstudio/en-US/a4fad4c3-6d18-41fc-82b7-1f3031349837/get-日の出・アンド・日没時間ベース・オン・緯度経度?フォーラム= csharpgeneral の

https://gist.github.com/cstrahan/767532する

http://pointofint.blogspot.com/ 2014/06 /日の出・アンド・サンセット・イン・c.html

ます。http://yaddb.blogspot。 COM / 2013/01 /どのようツー計算・日の出-と-sunset.html

https://forums.asp.net/トン/ 1810934.aspx?日の出+と+サンセット+タイミング+計算+

のhttp:// WWW。 ip2location.com/tutorials/display-sunrise-sunset-time-using-csharp-and-mysql-databaseする

http://en.pudn.com/downloads270/sourcecode/窓/ CSHARP / detail1235934_en.htmlする

http://regator.com/p/25716249/c_class_for_calculating_sunrise_and_sunset_timesする

http://forums.xkcd.com/viewtopic.php?t=102253

http://www.redrok.com/solar_position_algorithm.pdfする

http://sidstation.loudet.org/sunazimuth-en.xhtmlする

https://sourceforge.net/directory/os:windows /?Q =日の出/設定%20times

https://www.nuget.org/packages/SolarCalculator/する

http://www.grasshopper3d.com/forum/topics/solar-計算-プラグインする

これは私がずっと前プラネットソースコードのためにしたが、そのサイトにデータが失われたので、幸いにも、私は別の場所に保存されたプロジェクトだった。

https://github.com/DouglasAllen/SunTimes.VSCS.Netする

この骨子を使用していますプラス

https://gist.github.com/DouglasAllen/c682e4c412a0b9d8f536b014c1766f20する

今それを行うための手法の簡単な説明のために。

あなたがお住まいの地域のための真太陽正午または輸送を必要とする任意の日のための

最初ます。

そのアカウントにローカル経度を取ります。それはちょうど15で割ることによって、時間に変換することができる。

これは、後であなたがズールーゾーン時間またはゼロ経度からですどのくらいの時間である。

これは12:00 PMまたは正午から始まります。

と経度から算出したお時間でます。

今難しい部分。あなたは時間の式を計算する方法が必要になります。

つまり、太陽の周りに地球の傾きと軌道による時間差である。

これはあなたのアイデアを与えるだろう... https://en.wikipedia.org/wiki/Equation_of_time

しかし、彼らははるかに簡単である式を有する.... https://en.wikipedia.org /ウィキ/ Sunrise_equationする

この男は、多くの人で行くか、買う、いくつかの本を持っています。 :-D https://en.wikipedia.org/wiki/Jean_Meeusする

あなたの平均太陽トランジットのためにあなたの最初の計算を使用して計算します JDN ... https://en.wikipedia.org/wiki/Julian_dayする

これは、ユリウス世紀の時間としてすべての角度の式で使用されます https://en.wikipedia.org/wiki/Julian_year_(astronomy)

https://en.wikipedia.org/wiki/Epoch_(astronomy)

これは、基本的にあなたのJDNマイナスなJ2000や2451545.0としてエポックです あなたのユリウス世紀またはTを与えること36525.0で割っすべて これは、パラメータとしてトンを持っているほとんどの式のために使用されます。時々 ジュリアン千年が使用されています。その場合には、それは3652500.0です。

トリックは、あなたが時間の方程式を解決するため、これらの角度の計算式を見つけることです。

次に、あなたの本当の太陽のトランジットを取得し、半日を引くか、お住まいの地域のために太陽光の半日を追加します。あなたは答えとソフトウェアで周りの人を見つけることができます。

あなたが行く何かを得れば、

あなたは倍またはオンライン計算のための検索に対してそれを確認することができます。

私は、これはあなたが軌道に乗るには十分であると思います。そこライブラリは、あらゆる場所にあるが、それはあなた自身の作ることは難しいことではありません。私はやったが、それはRubyであります。 それは有用であると証明できた.... https://github.com/DouglasAllen/gem-equationoftimeする

幸運!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top