Readable Date and Time from Sun.GetDateTime in Python

Hi All,

I can access the Rhino Sun date and time in Python in Rhino or in Python in Grasshopper with this simple code.

from Rhino import RhinoDoc as rhdoc
from System import DateTime as datetime
sun = rhdoc.ActiveDoc.Lights.Sun
DT = sun.GetDateTime

but if i try to print DT it just returns
<built-in method GetDateTime of Sun Object at 0x00000000000002c>
Unlike when i print the sun vector and it returns the vector

I realise i may need to convert the system time to a formatted string, but not had much luck with that using system.datetime methods I just get runtime errors, that the built-in function or method has no attribute when it give it DT

Here’s the link to the RhinoCommon API (Working in Rhino V5 mind)

Hi @mattgaydon,
This works in Rhino 6, not sure about 5:

import System
import Rhino

sun = Rhino.RhinoDoc.ActiveDoc.Lights.Sun
dateTimeKind = System.DateTimeKind.Utc
#dateTimeKind = System.DateTimeKind.Local

dateTime = sun.GetDateTime(dateTimeKind)

print dateTime
print dateTime.TimeOfDay
print dateTime.Hour
print dateTime.Day

Yeap that works in RH 5 also.
I can also see why my code was not working as expected.
Thanks

One quick thing is there a way to just pull the Date in the same way as TimeOfDay

EDIT:
Solved it using .ToString rather than print to format it

date = dateTime.ToString("dd/MM/YY") 
#01/06/20

time = dateTime.ToString("HH:mm")
#09:00
1 Like