2008-02-10, 07:19 PM
The date carried for EPG info in a DVB broadcast is encoded as a Modified Julian Date. The document I have gives the following formulae to convert to Year, Month and Day components.
Console output:
Cheers,
Brian
Quote:a) To find Y, M, D from MJDThe following is my C# interpretation but my day result is always one day ahead, i.e., today is the 10th but my code is returning D=11.
Y' = int [ (MJD - 15 078,2) / 365,25 ]
M' = int { [ MJD - 14 956,1 - int (Y' Ã 365,25) ] / 30,6001 }
D = MJD - 14 956 - int (Y' Ã 365,25) - int (M' Ã 30,6001)
If M' = 14 or M' = 15, then K = 1; else K = 0
Y = Y' + K
M = M' - 1 - K Ã 12
Code:
int MJD = (start_time[0] * 256) + start_time[1];
int Y1 = Convert.ToInt32((MJD - 15078.2) / 365.25);
int M1 = Convert.ToInt32((MJD - 14956.1 - Convert.ToInt32(Y1 * 365.25)) / 30.6001);
int D = MJD - 14956 - Convert.ToInt32(Y1 * 365.25) - Convert.ToInt32(M1 * 30.6001);
int K = 0;
if ((M1 == 14) || (M1 == 15))
K = 1;
int Y = Y1 + K;
int M = M1 - 1 - (K * 12);
Console output:
Quote:MJD: 54506 Y1: 108 M1: 3 K: 0 Y: 108 M: 2 D: 11Can anybody see what's wrong with my code.
Cheers,
Brian