man mktime
and
man strftime
I just want to know the in between process.
seconds = epoch MOD 60;
epoch = epoch / 60;
minutes = epoch MOD 60;
epoch = epoch / 60;
hours = epoch MOD 24;
epoch = epoch / 24;
-- Now the epoch variable actually holds the number of days since 1/1/1970
leapdays = (epoch + 672) / 1461;
year = (epoch - leapdays) / 365;
epoch = epoch - ((year * 365) + ((year + 1) / 4));
-- Now the epoch variable actually holds the number of days since the start of the year
month = 1;
if (epoch > 31) {
epoch = epoch - 31;
month = 2;
febDays = 28 + (((year + 1) MOD 4) / 3);
if (epoch > febDays) {
epoch = epoch - febDays;
month = 3;
if (epoch > 31) {
epoch = epoch - 31;
month = 4;
if (epoch > 30) {
epoch = epoch - 30;
month = 5;
-- Continue along this line for each month of the year
}
}
}
}
year = year + 1970;
dayOfMonth = epoch;
-- Output the result. You would do better formatting than the below but again I don't know Map Basic
print dayOfMonth + "/" + month + "/" + year + " " + hour + ":" + minute + ":" + second;
I haven't tested the above code, but it should be pretty much right. Note though that it will fail for dates after 28 Feb 2100 and probably for dates before 1 Mar 1900, as it doesn't include the special leap day handling for years evenly divisible by 100. If you really want that, it would require quite a bit more logic which I will leave up to you to work out!!
but i want to know about how to find the exact month of given epoch timeYou are missing the point.... the above *IS* the way to find that out. Trust me, if there was an easier way, I wouldn't have spent the time doing all the above for you. I thought it would be pretty obvious to see that there is no magic solution to this. Different months have different numbers of days in them, so any logic will complicated by this. (along with the fact that leap days complicate things further)
// Create the month array
int days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) // all the correct leap year checks
days_in_month[1]++; // Add 1 to February
month = 0; // 0 is January, we'll fix that later
day = day_of_year; // start will all the days
// As long as there are too many days, we need to add a month
while (days > days_in_month[month])
{
days = days - days_in_month[month];
month = month + 1;
}
month = month + 1; // This makes 1 be January, 2 be February, etc
When the loop exits, month will be the correct month, and day will be the correct day of the month
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
groovy example issue | 10 | 90 | |
Looking for example pivot year code used in Y2K | 4 | 61 | |
Is there any way to copy all SSRS reports/datasets/data sources to new server? | 3 | 52 | |
Support for Notepad++ (including downloading & installing a plugin) | 5 | 68 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
12 Experts available now in Live!