Conversion from java to c#

  • Thread starter Thread starter daniel li
  • Start date Start date
D

daniel li

I am working with some java/.net conversion project and I need to
convert the following method into C#.

private java.sql.Date convertDate( Calendar calendar )
{
// calendar .getTime() returns a util.Date and I need to
// construct a
// sql.Date object. So call getTime() on the util.Date
// object to return
// a long representing milliseconds.
return new java.sql.Date( calendar.getTime().getTime() );
}

Does anybody know the equivalence in C# that will return
a long representing milliseconds?
Thanks
Daniel




*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
daniel li said:
I am working with some java/.net conversion project and I need to
convert the following method into C#.

private java.sql.Date convertDate( Calendar calendar )
{
// calendar .getTime() returns a util.Date and I need to
// construct a
// sql.Date object. So call getTime() on the util.Date
// object to return
// a long representing milliseconds.
return new java.sql.Date( calendar.getTime().getTime() );
}

Does anybody know the equivalence in C# that will return
a long representing milliseconds?

The important thing is that it's milliseconds since Jan 1st 1970. The
easiest way is to create a DateTime of Jan 1st 1970, and subtract that
from your DateTime, and then use TimeSpan.TotalMilliseconds. Don't
forget to think about timezones, of course...
 
Thanks for this reply, and I still have some questions.
1 what do you mean by 'The important thing is that it's milliseconds
since Jan 1st 1970.'?
2 Could you be kindly show me some code structure?
Thanks.

daniel

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
daniel li said:
Thanks for this reply, and I still have some questions.
1 what do you mean by 'The important thing is that it's milliseconds
since Jan 1st 1970.'?

That's what java.util.Date.getDate() returns.
2 Could you be kindly show me some code structure?

DateTime jan1970 = new DateTime (1970, 1, 1);

long millis = (long) ((myDateTime-jan1970).TotalMilliseconds);
 
Back
Top