Select to view content in your preferred language

Converting Date.Now into ITime

1126
4
12-02-2011 06:37 AM
MeToo
by
Deactivated User
How does one convert the current date and/or time (Date.Now) into a format compatible with Esri's ITime interface?

Thanks,
Dennis
0 Kudos
4 Replies
NeilClemmons
Honored Contributor
I've never used it but it looks like you would just call one of the Set methods on the interface.  For instance, call SetFromCurrentLocalTime sounds like it would set the time referenced by the object to the current time.
0 Kudos
MeToo
by
Deactivated User
Thanks Neil:

Your suggestion sounds logical enough, despite a cryptic help system description...

I am getting a System.NullReferenceException: Object reference not set to an instance of an object
error message with the following code. Any idea of what's wrong with it?

    Dim theLocalTime As ESRI.ArcGIS.esriSystem.ITime = New ESRI.ArcGIS.esriSystem.Time
    theLocalTime.SetFromCurrentLocalTime()    '<=> Setting the time object to .NET's Now?
    MsgBox("theLocalTime.ToShortDateString: " & theLocalTime.ToShortDateString)

Thanks again,
Dennis
0 Kudos
NeilClemmons
Honored Contributor
I don't see a method on the interface named ToShortDateString.  Where are you getting that from?  I just created a quick sample command and the following code works for me.

        Dim t As ITime = New Time
        t.SetFromCurrentLocalTime()
        MsgBox(t.QueryTimeString(esriTimeStringFormat.esriTSFYearThruMinuteWithDash))
0 Kudos
MeToo
by
Deactivated User
Neil:

You are right. I had originally developed a procedure that accepted a .NET Date, but changed it to the ArcGIS ITime without realizing I was invalidating the ToShortDateString member. Visual Studio only caught it at runtime.

Thanks,
Dennis
0 Kudos