Conversion from java to c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • daniel li

    Conversion from java to c#

    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.getTim e().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!
  • Jon Skeet [C# MVP]

    #2
    Re: Conversion from java to c#

    daniel li <daniel_l55446@ yahoo.com> wrote:[color=blue]
    > 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.getTim e().getTime() );
    > }
    >
    > Does anybody know the equivalence in C# that will return
    > a long representing milliseconds?[/color]

    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.TotalM illiseconds. Don't
    forget to think about timezones, of course...

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • daniel li

      #3
      Re: Conversion from java to c#

      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!

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Conversion from java to c#

        daniel li <daniel_l55446@ yahoo.com> wrote:[color=blue]
        > 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.'?[/color]

        That's what java.util.Date. getDate() returns.
        [color=blue]
        > 2 Could you be kindly show me some code structure?[/color]

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

        long millis = (long) ((myDateTime-jan1970).TotalM illiseconds);

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...