code: def datetime_to_json(pydt, manager):
      """Serialize a Python datetime object to json.
  
      Instantiating a JavaScript Date object with a string assumes that the
      string is a UTC string, while instantiating it with constructor arguments
      assumes that it's in local time:
  
      >>> cdate = new Date('2015-05-12')
      Mon May 11 2015 20:00:00 GMT-0400 (Eastern Daylight Time)
      >>> cdate = new Date(2015, 4, 12) // Months are 0-based indices in JS
      Tue May 12 2015 00:00:00 GMT-0400 (Eastern Daylight Time)
  
      Attributes of this dictionary are to be passed to the JavaScript Date
      constructor.
      """
      if pydt is None:
          return None
      else:
          try:
              utcdt = pydt.astimezone(dt.timezone.utc)
          except (ValueError, OSError):
              # If year is outside valid range for conversion,
              # use it as-is
              utcdt = pydt
          return dict(
              year=utcdt.year,
              month=utcdt.month - 1,  # Months are 0-based indices in JS
              date=utcdt.day,
              hours=utcdt.hour,  # Hours, Minutes, Seconds and Milliseconds
              minutes=utcdt.minute,  # are plural in JS
              seconds=utcdt.second,
              milliseconds=utcdt.microsecond / 1000,
          )
  
imports: import re
  import traitlets
  import datetime
label_desc: Use image node_id 1 for calling a global function with example usage: datetime_to_json(pydt, manager) and returns: None, dict