Whitepaper
Docs
Sign In
Tool
Tool
Current time in Shanghai
Tool ID
current_time_in_shanghai
Creator
@unadvised
Downloads
130+
Get the current Asia/Shanghai time(获取当前的 亚洲/上海时间)
Get
README
No README available
Tool Code
Show
from datetime import datetime, timezone, timedelta class Tools: """ CW_NTP Tool to retrieve and display the current date and time in Shanghai, Asia (UTC+8). Note: This implementation does not use an NTP client due to limitations within the Open WebUI environment. Time accuracy relies on the system clock. """ def get_shanghai_time(self) -> str: """ Calculates the current time for Shanghai, Asia (UTC+8) based on the system clock. """ try: current_utc_time = datetime.now( timezone.utc ) # More efficient than replacing timezone info shanghai_time = current_utc_time + timedelta(hours=8) return shanghai_time.strftime("%A, %B %d, %Y %H:%M:%S (Shanghai Time)") except Exception as e: # More specific error handling would be ideal, but limited by Open WebUI return f"Error calculating Shanghai time: {e}" def preface_with_time(self, text: str) -> str: """ Prepends the calculated Shanghai timestamp to the given text. """ current_time = self.get_shanghai_time() return f"{current_time}\n\n{text}"