Whitepaper
Docs
Sign In
Tool
Tool
GetTimeDate
Tool ID
gettime
Creator
@bwoodruff2021
Downloads
540+
Get the current date and/or time with timezone valve/setting from local machine with UTC time setting.
Get
README
No README available
Tool Code
Show
from datetime import datetime, timezone from zoneinfo import ZoneInfo # Requires Python 3.9+ from pydantic import BaseModel, Field class Tools: class Valves(BaseModel): desired_timezone: str = Field( default="America/New_York", description="Set Time Zone. List of time zones can be located at: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones", ) class UserValves(BaseModel): pass def __init__(self): self.valves = self.Valves() self.user_valves = self.UserValves() def get_current_date(self) -> str: """ Get the current date. :return: The current date as a string. """ # current_date = datetime.now().strftime("%A, %B %d, %Y") # return f"Today's date is {current_date}" now_utc = datetime.now(timezone.utc) tz = ZoneInfo(self.valves.desired_timezone) now_desired = now_utc.astimezone(tz) current_date = now_desired.strftime("%A, %B %d, %Y") return f"Today's date is {current_date}" def get_current_time(self) -> str: """ Get the current time. :return: The current time as a string. """ # current_time = datetime.now().strftime("%H:%M:%S") # return f"Current Time: {current_time}" now_utc = datetime.now(timezone.utc) tz = ZoneInfo(self.valves.desired_timezone) now_desired = now_utc.astimezone(tz) formatted_time = now_desired.strftime("%I:%M %p") return f"The current time is {formatted_time}" # Usage # tools = Tools() # print("Today's date:", tools.get_current_date()) # print("Current Time:", tools.get_current_time())