Convert Grasshopper Clock DateTime to datetime

I have issues converting Grasshopper Clock DateTime (type hint) to datetime in ghpython. Panel shows me hh:mm:ss but it seams there is also a default date attached. So I wonder how I get date from datetime and concatenate it to the the external Clock input. Last but not least format datetime from it manually…

Any Help or explanations are appreciated :slight_smile:

Not sure but I’m using this:

from time import localtime, strftime

a=strftime("%a, %d %b %Y %H:%M:%S", localtime())
b=strftime("%y_%m_%d", localtime())

print a
print b

Thx but I use the grasshopper clock from param > inputs to initiate a timedelta calculation. So I need datetime I guess. I am just confused with the different time types…

solved my issues kind of… not what i wanted but works! … in progess… part of a bigger context…
input ist DateTime (type hint) from Clock (prm >input) as trigger.
had chatgpt do the revison :slight_smile: as my python skills are still limited.

import datetime

def calculate_timedelta():
    default_deadline = datetime.datetime(2023, 3, 8)
    timedelta_to_default = default_deadline - datetime.datetime.now()
    if timedelta_to_default.total_seconds() <= 0:
        return "time is up"
    days = timedelta_to_default.days
    hours, seconds = divmod(timedelta_to_default.seconds, 3600)
    minutes, seconds = divmod(seconds, 60)
    formatted_timedelta = "{} days {} hours {} minutes".format(days, hours, minutes)
    return formatted_timedelta

def toggle_login(clock):
    if "logged_in" not in globals():
        globals()["logged_in"] = False
    if "start_time" not in globals():
        globals()["start_time"] = None
    if clock and clock != globals().get("last_clock", None):
        globals()["last_clock"] = clock
        formatted_timedelta = calculate_timedelta()
        if formatted_timedelta == "time is up":
            print(formatted_timedelta)
        elif not globals()["logged_in"]:
            globals()["logged_in"] = True
            globals()["start_time"] = clock
            print("Logged in\n\nTimestamp @ {}".format(datetime.datetime.now().strftime('%m/%d/%Y %H:%M:%S')))
        else:
            globals()["logged_in"] = False
            end_time = clock
            duration = end_time - globals()["start_time"]
            print("Logged out\n\nTime elapsed: {}\nT-Minus: {}".format(duration, formatted_timedelta))


toggle_login(log)