Converting Date.Now into ITime

866
4
12-02-2011 06:37 AM
MeToo
by
New Contributor
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
Regular Contributor III
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
New Contributor
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
Regular Contributor III
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
New Contributor
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