currentDateTime
Retrieve the current date and time for a specified timezone or default to UTC. Input a valid IANA timezone name like 'America/New_York' to get the accurate local time.
Instructions
Get Current Date and time for timezone. if timezone is not passed default to UTC
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone | No | The timezone should be a valid IANA timezone name like "America/New_York" or "Asia/Kolkata" |
Implementation Reference
- src/server.ts:103-115 (handler)Handler function that takes timezone input (optional, defaults to UTC) and returns the current date and time formatted using Intl.DateTimeFormat.(data) => { const formatter = new Intl.DateTimeFormat("en-US", { timeZone: data.timezone || "UTC", dateStyle: "full", timeStyle: "long", }); return { content: [{ type: "text", text: formatter.format(new Date()), }] } }
- src/server.ts:100-102 (schema)Zod schema defining the input parameters for the currentDateTime tool: optional nullable timezone string.{ timezone: z.string().optional().nullable().describe(`The timezone should be a valid IANA timezone name like "America/New_York" or "Asia/Kolkata"`), },
- src/server.ts:99-116 (registration)Registration of the currentDateTime tool on the MCP server, specifying name, description, input schema, and inline handler function.server.tool("currentDateTime", "Get Current Date and time for timezone. if timezone is not passed default to UTC", { timezone: z.string().optional().nullable().describe(`The timezone should be a valid IANA timezone name like "America/New_York" or "Asia/Kolkata"`), }, (data) => { const formatter = new Intl.DateTimeFormat("en-US", { timeZone: data.timezone || "UTC", dateStyle: "full", timeStyle: "long", }); return { content: [{ type: "text", text: formatter.format(new Date()), }] } } );