lblinc
asked on
Java to C# - 500 pts. less than 15 lines
Please help translate these few lines of java code into C# ...
//Gets a calendar using the default time zone and locale. Calendar returned is based on the current time in the default time zone with the default locale.
Calendar cal = Calendar.getInstance();
long time = 1036074738312;
int day = 31;
cal.setTimeInMillis(time); // Sets this Calendar's current time from the given long value. long millis param is the new time in UTC milliseconds from the epoch.
if (cal.get(Calendar.DAY_OF_M ONTH) == day) {
... do some stuff here ...
}
//Gets a calendar using the default time zone and locale. Calendar returned is based on the current time in the default time zone with the default locale.
Calendar cal = Calendar.getInstance();
long time = 1036074738312;
int day = 31;
cal.setTimeInMillis(time);
if (cal.get(Calendar.DAY_OF_M
... do some stuff here ...
}
ASKER
Using time = 1036074738312 above, it appears is returning a year of 0033, when actually i believe that 1036074738312 represents a day (31) from the year of 2003.
What about adding the basetime to your DateTime cal in order to account for the time before 1970 ?
DateTime baseTime = new DateTime(1970, 1, 1, 0, 0, 0);
Can you please consider that in your answer? Thanks.
What about adding the basetime to your DateTime cal in order to account for the time before 1970 ?
DateTime baseTime = new DateTime(1970, 1, 1, 0, 0, 0);
Can you please consider that in your answer? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent. Works perfect. ;))
long time = 1036074738312;
int day = 31;
DateTime cal = new DateTime(time * 10000, DateTime.Now.Kind);
if (cal.Day == day)
{
//Do Stuff....
}
Hope that helps, if you have any questions, just post a comment