I am studying a method I have found in an application called 'getDateTime'. It returns a date and time as one integer. This is then converted by the app and displayed on a label in 24 hour format.
I am not sure how the method is converting the integer it returns - it will not be possible to see this code.
What I can do is override the returned integer and see what date and time is displayed to try and figure out how it is formatted. I would like to be able to convert any date and time to an int of the same format.
Here are some random overrides I did, and what the corresponding printed result was. I have also recorded when the app crashed to give an idea of when the format may be invalid:
If you need anymore examples to figure out the format, please ask away! I just can't see any correlation, other than the fact that changing the right most digit can be used to change the current day.
It seems that the components of the date (year, month, day, hour, minute) are packed into fields of specific width (similar to the way dates were stored in a FAT directory entry ).
This method will pack the information into the required format:
public static int packTimeFields(int year, int month, int day, int hour, int minute) {
checkRange("year", year, 2000, 2127);
checkRange("month", month, 1, 12);
checkRange("day", day, 1, 31);
checkRange("hour", hour, 0, 23);
checkRange("minute", minute, 0, 59);
return day + (month-1) * 32 + (year-2000) * 512 + minute * 65536 + hour * 65536 * 64;
}
private static void checkRange(String name, int value, int min, int max) {
if (value < min || value > max)
throw new IllegalArgumentException(name+" "+value+" is not in valid range "+min+"..."+max);
}
This code nicely explains the shown examples except
1129601 - 01 March 2030 0:17
I would expect this to be
1129601 - 01 May 2030 0:17
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.