def datetime_to_int(datetime):
    """Convert datetime to 17 digit integer with millisecond precision."""
    template = (
        '{year:04d}'
        '{month:02d}'
        '{day:02d}'
        '{hour:02d}'
        '{minute:02d}'
        '{second:02d}'
        '{millisecond:03d}'
    )
    priority = int(
        template.format(
            year=datetime.year,
            month=datetime.month,
            day=datetime.day,
            hour=datetime.hour,
            minute=datetime.minute,
            second=datetime.second,
            millisecond=int(datetime.microsecond / 1000.0),
        )
    )
    return priority