Link to home
Start Free TrialLog in
Avatar of lblinc
lblincFlag for United States of America

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_MONTH) == day) {                  
       ...  do some stuff here ...
}
Avatar of kingtam2000
kingtam2000

From what I can judge, you could use DateTime instead of Calender and use the constructor, after converting the time in milliseconds into 100-nanosecond units to form what you want:
            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
Avatar of lblinc

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.
ASKER CERTIFIED SOLUTION
Avatar of kingtam2000
kingtam2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lblinc

ASKER

Excellent.   Works perfect.   ;))