Public Class Tester
Public Shared Sub Main
Dim phaseDay As Double
Dim result As String
phaseDay = MoonPhase(Now.ToUniversalTime)
result = "UTC is now: " & _
Now.ToUniversalTime.ToString("u") & vbNewLine & vbNewLine
If (phaseDay < 0) Then
result &= "Approx days until new moon: " & _
(-phaseDay).ToString("F1")
Else
result &= "Approx days since new moon: " & _
phaseDay.ToString("F1")
End If
Console.WriteLine(result)
End Sub
Public Shared Function MoonPhase(ByVal dateUtc As Date) As Double
Dim days As Double = dateUtc.Subtract(#1/1/1600#).TotalDays
Dim cycles As Double = days * 0.03386319 - 12.5
Return Math.IEEERemainder(cycles, 1.0) * 29.53059
End Function
End Class
|