Solved

Java to C# - 500 pts.  less than 15 lines

Posted on 2007-04-08
4
217 Views
Last Modified: 2010-04-15
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 ...
}
0
Comment
Question by:lblinc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:kingtam2000
ID: 18874041
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
0
 

Author Comment

by:lblinc
ID: 18874286
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.
0
 
LVL 3

Accepted Solution

by:
kingtam2000 earned 500 total points
ID: 18874294
Yes, I realised that the time would return a year of 0033, but I wasn't sure where you wanted to start from, as the epoch was slightly ambiguous.  But to account for the epoch, I would add the following line after the datetime constructor:
            cal = cal.AddYears(1970);
So, in full:
            long time = 1036074738312;
            int day = 31;
            DateTime cal = new DateTime(time * 10000, DateTime.Now.Kind);
            cal = cal.AddYears(1970);
            if (cal.Day == day)
            {
                //Do Stuff....
            }

Sorry about that, didn't check the epoch in terms of Java, if you have any further questions, just post another comment.
0
 

Author Comment

by:lblinc
ID: 18874338
Excellent.   Works perfect.   ;))
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question