Solved

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

Posted on 2007-04-08
4
216 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Suggested Courses

739 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