从现在是白天还是晚上的时间类型获取
Get from what type time is now Day or Night
是否有可能获得现在是什么类型的时间 --> 当前位置是白天还是晚上。例如,现在我在保加利亚,时间是 2:14 下午或 10:20 上午,这意味着现在是白天。 2.14 AM 或 11:20 PM 是晚上。在 .NET 中有方法可以在计算机上获取位置并告诉现在是晚上还是白天。
编辑:
澄清一下:夜晚是从日落开始,到日出结束
BCL 中没有任何内容可以直接 return sunset/sunrise 值。结果取决于地球上的实际位置,而不是 DateTime
文化。
也就是说,所有数学难题都已经写好了,所以您只需将现有算法翻译成适当的 C#。
参见示例C# Sunrise/Sunset with latitude/longitude
这有点取决于你所说的白天和黑夜。
如果您在给定位置定义夜晚 = 在日落和日出之间,请考虑使用 Nuget 包太阳能计算器。这使得计算为 "simple comme bonjour"
来自项目网站的示例:
芝加哥的日出
using System;
using Innovative.SolarCalculator;
// ***
// *** Geo coordinates of Oak Street Beach in Chicago, IL
// ***
// *** NOTE: the .Date is not necessary but is included to demonstrate that time input
// *** does not affect the output. Time will be returned in the current time zone so it
// *** will need to be adjusted to the time zone where the coordinates are from (there
// *** are services that can be used to get time zone from a latitude and longitude position).
// ***
TimeZoneInfo cst = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
SolarTimes solarTimes = new SolarTimes(DateTime.Now.Date, 41.9032, -87.6224);
DateTime sunrise = TimeZoneInfo.ConvertTimeFromUtc (solarTimes.Sunrise.ToUniversalTime(), cst);
// ***
// *** Display the sunrise
// ***
Console.WriteLine ("View the sunrise across Lake Michigan from Oak Street Beach in Chicago at {0} on {1}.", sunrise.ToLongTimeString(), sunrise.ToLongDateString());
密歇根的日落
// ***
// *** Geo coordinates of Benton Harbor/Benton Heights in Michigan
// ***
TimeZoneInfo est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
SolarTimes solarTimes = new SolarTimes(DateTime.Now, 42.1543, -86.4459);
DateTime sunset = TimeZoneInfo.ConvertTimeFromUtc(solarTimes.Sunset.ToUniversalTime(), est);
// ***
// *** Display the sunset
// ***
Console.WriteLine("View the sunset across Lake Michigan from Benton Harbor Michigan at {0} on {1}.", sunset.ToLongTimeString(), sunset.ToLongDateString());
我知道这是旧的,但你真的应该检查一下 CoordinateSharp。它可以通过 Nuget 获得并且非常易于使用。
示例
//Coordinate Lat, Long, Date
Coordinate c = new Coordinate(25,35,DateTime.Now);
c.CelestialInfo.IsSunUp; //Returns Boolean
是否有可能获得现在是什么类型的时间 --> 当前位置是白天还是晚上。例如,现在我在保加利亚,时间是 2:14 下午或 10:20 上午,这意味着现在是白天。 2.14 AM 或 11:20 PM 是晚上。在 .NET 中有方法可以在计算机上获取位置并告诉现在是晚上还是白天。
编辑: 澄清一下:夜晚是从日落开始,到日出结束
BCL 中没有任何内容可以直接 return sunset/sunrise 值。结果取决于地球上的实际位置,而不是 DateTime
文化。
也就是说,所有数学难题都已经写好了,所以您只需将现有算法翻译成适当的 C#。
参见示例C# Sunrise/Sunset with latitude/longitude
这有点取决于你所说的白天和黑夜。
如果您在给定位置定义夜晚 = 在日落和日出之间,请考虑使用 Nuget 包太阳能计算器。这使得计算为 "simple comme bonjour"
来自项目网站的示例:
芝加哥的日出
using System;
using Innovative.SolarCalculator;
// ***
// *** Geo coordinates of Oak Street Beach in Chicago, IL
// ***
// *** NOTE: the .Date is not necessary but is included to demonstrate that time input
// *** does not affect the output. Time will be returned in the current time zone so it
// *** will need to be adjusted to the time zone where the coordinates are from (there
// *** are services that can be used to get time zone from a latitude and longitude position).
// ***
TimeZoneInfo cst = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
SolarTimes solarTimes = new SolarTimes(DateTime.Now.Date, 41.9032, -87.6224);
DateTime sunrise = TimeZoneInfo.ConvertTimeFromUtc (solarTimes.Sunrise.ToUniversalTime(), cst);
// ***
// *** Display the sunrise
// ***
Console.WriteLine ("View the sunrise across Lake Michigan from Oak Street Beach in Chicago at {0} on {1}.", sunrise.ToLongTimeString(), sunrise.ToLongDateString());
密歇根的日落
// ***
// *** Geo coordinates of Benton Harbor/Benton Heights in Michigan
// ***
TimeZoneInfo est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
SolarTimes solarTimes = new SolarTimes(DateTime.Now, 42.1543, -86.4459);
DateTime sunset = TimeZoneInfo.ConvertTimeFromUtc(solarTimes.Sunset.ToUniversalTime(), est);
// ***
// *** Display the sunset
// ***
Console.WriteLine("View the sunset across Lake Michigan from Benton Harbor Michigan at {0} on {1}.", sunset.ToLongTimeString(), sunset.ToLongDateString());
我知道这是旧的,但你真的应该检查一下 CoordinateSharp。它可以通过 Nuget 获得并且非常易于使用。
示例
//Coordinate Lat, Long, Date
Coordinate c = new Coordinate(25,35,DateTime.Now);
c.CelestialInfo.IsSunUp; //Returns Boolean