C#日出/日落与纬度/经度
在C#中有没有一种方法可以计算给定的纬度和经度,即太阳在给定的一天内落下和升起的时间?Javascript计算。现在你只需要移植C#日出/日落与纬度/经度,c#,latitude-longitude,C#,Latitude Longitude,在C#中有没有一种方法可以计算给定的纬度和经度,即太阳在给定的一天内落下和升起的时间?Javascript计算。现在你只需要移植 编辑:计算在现在的源代码中 编辑:是到源代码的直接链接。无需浏览html。从以下信息开始: 我正在用它来编写一个ruby脚本,它仍在制作中。 我很难理解朱利安的多重约会 有一件事很清楚,那就是你应该去寻找准确的太阳凌日时间。 然后减去并加上基于 在你的纬度和太阳赤纬上。哦一定要包括太阳能 中心和地球折射。地球似乎是个魔术师。你需要一个公式,其中包括时间方程,以考
编辑:计算在现在的源代码中
编辑:是到源代码的直接链接。无需浏览html。从以下信息开始: 我正在用它来编写一个ruby脚本,它仍在制作中。 我很难理解朱利安的多重约会 有一件事很清楚,那就是你应该去寻找准确的太阳凌日时间。 然后减去并加上基于 在你的纬度和太阳赤纬上。哦一定要包括太阳能
中心和地球折射。地球似乎是个魔术师。你需要一个公式,其中包括时间方程,以考虑地球-月球系统绕太阳的偏心轨道。您需要使用具有适当基准点的坐标,如WGS84或NAD27或类似的东西。你需要使用朱利安历法,而不是我们每天使用的那个,这样才能保证这些时间是正确的。这不是一件容易在一秒钟内猜到的事情。我想在我的位置有一个时间,阴影长度等于任意高度。当太阳在正午前后高于地平线60度时,这种情况应该每天发生两次。另外,据我所知,你只需要每年增加一天就可以得到恒星时间,所以如果你想增加你的时钟频率X 366.25/365.25,你现在可能有一个恒星时钟而不是民用时钟???“数学是有权势的人编写宇宙的语言”另一个好的JS实现是
代码行的数量是可管理的,因此移植到其他语言(C#)当然是可能的。我制作了一个快速Python脚本来实现这一点: 我还没有将它封装在一个类中,但它可能对其他人有用
编辑:开源太棒了,因为提交了基本脚本,有人将其包装在一个模块中,另一个添加了cli接口!感谢mbideau和nfischer的贡献 我使用NAA javascript和c#在c#中创建了这个库 我对这两个站点进行了测试,它显示的时间与站点显示的时间完全相同
对此公认的答案是JavaScript实现,它不适合我的应用程序,因为我需要用C#进行计算 我使用了这个C代码:,我在这里根据日出/日落时间对其进行了验证:
如果我将秒舍入到最接近的分钟,C#实现的日出和日落时间将与timeanddate.com上显示的相应值匹配,包括夏令时的情况。尽管代码有点难以理解(除非您也想要月相数据),所以我将对其进行重构,以实现我现在所需的具体操作。数字是正确的。如果您喜欢外部服务,您可以使用这个漂亮且免费的日出和日落时间API: 我已经使用它的几个项目,它的工作非常好,数据似乎非常准确。只需执行一个HTTP GET请求 接受的参数:
- 纬度:以十进制度数表示的纬度。必需的
- lng:以十进制度数表示的经度。必需的
- 日期:YYYY-MM-DD格式的日期。还接受其他日期格式,甚至是相对日期格式。如果不存在,则日期默认为当前日期。可选
- 回调:JSONP响应的回调函数名。可选
- 格式化:0或1(默认为1)。响应中的时间值将按照ISO 8601表示,日长将以秒表示。可选
响应包括日出和日落时间以及黄昏时间。此API似乎适合我:
VB.Net版的dotsa答案,也可以自动确定时区 输出(通过观看今晚的日落检查): 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
Sun公共模块
'使用本地系统时区获取纬度和经度的日出时间
函数日出(纬度加倍,经度加倍)作为日期时间
Dim julian As Double=JulianDay(DateTime.Now)
Dim上升为双精度=UTC(朱利安、纬度、经度)
Dim timehere As DateTime=DateTime.Now
将本地设置为TimeZoneInfo=TimeZoneInfo.local
Dim dst作为布尔值=local.IsDaylightSavingTime(timehere)
Dim分区为整数=local.BaseUtcOffset().TotalHours
Dim结果为DateTime=getDateTime(上升、区域、时间、dst)
返回结果
端函数
'使用本地系统时区获取纬度、经度的日落时间
将日落(纬度加倍,经度加倍)作为日期时间
Dim julian As Double=JulianDay(DateTime.Now)
暗度上升为Double=SunSetUTC(朱利安、纬度、经度)
Dim timehere As DateTime=DateTime.Now
将本地设置为TimeZoneInfo=TimeZoneInfo.local
Dim dst作为布尔值=local.IsDaylightSavingTime(timehere)
Dim分区为整数=local.BaseUtcOffset().TotalHours
Dim结果为DateTime=getDateTime(上升、区域、时间、dst)
返回结果
端函数
'将弧度角度转换为度
公共职能学位(双学位)双学位
返回(180.0*angelrad/Math.PI)
端函数
'将度角转换为弧度
公共功能弧度(角度度为双精度)为双精度
返回(数学PI*角度度/180.0)
端函数
*姓名:朱丽安代
'*类型:函数
“*目的:朱利安日自公历日起
“*论点:
“*年份:4位数年份
“*月份:一月=1
*日期:1-31
'*返回值:
“*与日期相对应的朱利安日
“*注:
“*返回当天开始时的编号。分数天应该是
“*稍后添加。
公共函数JulianDay(年为整数,月为I)
Celestial cel = Celestial.CalculateCelestialTimes(85.57682, -70.75678, new DateTime(2017,8,21));
Console.WriteLine(cel.SunRise.Value.ToString());
SolarTimes solarTimes = new SolarTimes(DateTime.Now, la, lo);
DateTime sr = solarTimes.Sunrise;
DateTime dt = Convert.ToDateTime(sr);
textblockb.Text = dt.ToString("h:mm:ss");
Install-Package SolarCalculator -Version 2.0.2