0

Metodo para convertir una fecha en formato Julian Date a dia, mes, año en C#

Posted by Jiro on 15:58

class Program {

public static void ExcelSerialDateToDMY(int nSerialDate, ref int nDay, ref int nMonth, ref int nYear)

{

//FUncion que calcula a partir de un entero en formato Julian Date el numero de dias , meses y años//
// Excel/Lotus 123 have a bug with 29-02-1900. 1900 is not a
// leap year, but Excel/Lotus 123 think it is…

if (nSerialDate == 60)
{
nDay = 29;
nMonth = 2;
nYear = 1900;
return;
}
else if (nSerialDate < 60)
{
// Because of the 29-02-1900 bug, any serial date
// under 60 is one off… Compensate.
nSerialDate++;
}

// Modified Julian to DMY calculation with an addition of 2415019
int l = nSerialDate + 68569 + 2415019;
int n = (int)((4 * l) / 146097);
l = l - (int)((146097 * n + 3) / 4);
int i = (int)((4000 * (l + 1)) / 1461001);
l = l - (int)((1461 * i) / 4) + 31;
int j = (int)((80 * l) / 2447);
nDay = l - (int)((2447 * j) / 80);
l = (int)(j / 11);
nMonth = j + 2 - (12 * l);
nYear = 100 * (n - 49) + i + l;

}

Copyright © 2009 SHAREPOINT FOUNDATION All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.