static void Main(string[] args) { int inYear = 1916; int day, month, year; DateTime date = new DateTime(inYear, 1, 1); date = date.AddDays(255); Calendar julian = new JulianCalendar(); Calendar gregorian = new GregorianCalendar(); if (inYear < 1918) { day = julian.GetDayOfMonth(date); month = julian.GetMonth(date); year = julian.GetYear(date); date = new DateTime(year, month, day); } else { if (inYear == 1918) { date = date.AddDays(-12); } day = gregorian.GetDayOfMonth(date); month = gregorian.GetMonth(date); year = gregorian.GetYear(date); date = new DateTime(year, month, day); } Console.WriteLine(date.ToString("dd.MM.yyyy")); Console.ReadKey(); }
public static SqlString Date2JulianMarkup(SqlBytes input) { if (input.IsNull) { return SqlString.Null; } byte[] inputBytes = input.Value; int year = (inputBytes[0] << 4 | inputBytes[1] >> 4) - 1024; int month = (inputBytes[1] & 0x0F) - 1; int day = inputBytes[2] >> 3; string result; DateTime date = new DateTime(year, month, day); JulianCalendar julianCalendar = new JulianCalendar(); int jYear = julianCalendar.GetYear(date); int jMonthOffset = julianCalendar.GetMonth(date) - 1; int jDay = julianCalendar.GetDayOfMonth(date); if (jYear == year) { result = "[Day[" + date_time_format_info.GetMonthName(month) + "-" + day + "|" + date_time_format_info.GetMonthName(month) + " " + day + "]] (O.S. " + date_time_format_info.GetMonthName(month) + " " + jDay + "), " + "[Year[" + year + "]]"; } else { result = "[Day[" + date_time_format_info.GetMonthName(month) + "-" + day + "|" + date_time_format_info.GetMonthName(month) + " " + day + "]], [Year[" + year + "|" + year + "]], (O.S. " + date_time_format_info.GetMonthName(month) + " " + jDay + ", " + jYear + ")"; } if ((inputBytes[2] & 0x02) == 0) { result = "circa " + result; } if ((inputBytes[2] & 0x04) == 0) { result = "? " + result; } return new SqlString(result); }
public static void Main() { Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK"); JulianCalendar jc = new JulianCalendar(); DateTime lastDate = new DateTime(1700, 2, 18, jc); Console.WriteLine("Last date (Gregorian): {0:d}", lastDate); Console.WriteLine("Last date (Julian): {0}-{1}-{2}\n", jc.GetDayOfMonth(lastDate), jc.GetMonth(lastDate), jc.GetYear(lastDate)); DateTime firstDate = lastDate.AddDays(1); Console.WriteLine("First date (Gregorian): {0:d}", firstDate); Console.WriteLine("First date (Julian): {0}-{1}-{2}", jc.GetDayOfMonth(firstDate), jc.GetMonth(firstDate), jc.GetYear(firstDate)); }
/// <summary> /// Converts the date in Gregorian Calendar to a date in Julian Calendar. /// </summary> /// <param name="date">Date in Gregorian Calendar</param> /// <returns> /// Date in Julian Calendar /// </returns> public static Date GregorianToJulian(Date date) { DateTime dt = new DateTime(date.Year, date.Month, (int)date.Day, new GregorianCalendar()); JulianCalendar julianCalendar = new JulianCalendar(); return(new Date( julianCalendar.GetYear(dt), julianCalendar.GetMonth(dt), julianCalendar.GetDayOfMonth(dt))); }
private static double CurrentJulianDate() { JulianCalendar cal = new JulianCalendar(); int isJanFeb = (14 - cal.GetMonth(DateTime.UtcNow)) / 12; int years = cal.GetYear(DateTime.UtcNow) + 4800 - isJanFeb; int monthsMod = cal.GetMonth(DateTime.UtcNow) + (12 * isJanFeb) - 3; double dayNumber = cal.GetDayOfMonth(DateTime.UtcNow) + Math.Floor((double)(153 * monthsMod + 2) / 5) + 365 * years + Math.Floor((double)years / 4) - 32083; double julianDate = dayNumber + ((double)cal.GetHour(DateTime.UtcNow) - 12) / 24 + (double)cal.GetMinute(DateTime.UtcNow) / 1440 + (double)cal.GetSecond(DateTime.UtcNow) / 86400; return(julianDate); }
public static void Main() { JulianCalendar julian = new JulianCalendar(); DateTime date1 = new DateTime(1905, 1, 9, julian); Console.WriteLine("Date ({0}): {1:d}", CultureInfo.CurrentCulture.Calendar, date1); Console.WriteLine("Date in Julian calendar: {0:d2}/{1:d2}/{2:d4}", julian.GetMonth(date1), julian.GetDayOfMonth(date1), julian.GetYear(date1)); }
public static void Main() { // Create an instance of the calendar. JulianCalendar myCal = new JulianCalendar(); Console.WriteLine(myCal.ToString()); // Create an instance of the GregorianCalendar. GregorianCalendar myGre = new GregorianCalendar(); // Display the MinSupportedDateTime and its equivalent in the GregorianCalendar. DateTime myMin = myCal.MinSupportedDateTime; Console.Write("MinSupportedDateTime: {0:D2}/{1:D2}/{2:D4}", myCal.GetMonth(myMin), myCal.GetDayOfMonth(myMin), myCal.GetYear(myMin)); Console.WriteLine(" (in Gregorian, {0:D2}/{1:D2}/{2:D4})", myGre.GetMonth(myMin), myGre.GetDayOfMonth(myMin), myGre.GetYear(myMin)); // Display the MaxSupportedDateTime and its equivalent in the GregorianCalendar. DateTime myMax = myCal.MaxSupportedDateTime; Console.Write("MaxSupportedDateTime: {0:D2}/{1:D2}/{2:D4}", myCal.GetMonth(myMax), myCal.GetDayOfMonth(myMax), myCal.GetYear(myMax)); Console.WriteLine(" (in Gregorian, {0:D2}/{1:D2}/{2:D4})", myGre.GetMonth(myMax), myGre.GetDayOfMonth(myMax), myGre.GetYear(myMax)); }