Skip to main content
Glama
TakanariShimbo

DateTime MCP Server

get_current_time

Retrieve current date and time in multiple formats like ISO, Unix, or custom. Supports timezone adjustments for accurate timestamp generation.

Instructions

Get the current date and time in various formats

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format for the datetime (optional, defaults to "iso" from env)
timezoneNoTimezone to use (optional, defaults to "UTC" from env)

Implementation Reference

  • Executes the get_current_time tool: parses arguments, formats current date/time using helpers, returns as text content or error.
    if (name === "get_current_time") { const format = (args as any)?.format || DATETIME_FORMAT; const timezone = (args as any)?.timezone || TIMEZONE; const now = new Date(); try { const formattedDate = formatDateTime(now, format, timezone); return { content: [ { type: "text", text: formattedDate, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error formatting date: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }
  • Defines the tool schema including input parameters for format and timezone with enums and descriptions.
    const GET_CURRENT_TIME_TOOL: Tool = { name: "get_current_time", description: "Get the current date and time in various formats", inputSchema: { type: "object", properties: { format: { type: "string", enum: ["iso", "unix", "unix_ms", "human", "date", "time", "custom"], description: `Output format for the datetime (optional, defaults to "${DATETIME_FORMAT}" from env)`, }, timezone: { type: "string", description: `Timezone to use (optional, defaults to "${TIMEZONE}" from env)`, }, }, }, };
  • src/index.ts:319-321 (registration)
    Registers the get_current_time tool by including it in the ListTools response.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [GET_CURRENT_TIME_TOOL], }));
  • Core helper function that formats the Date object into the requested format using Intl API or custom logic.
    function formatDateTime(date: Date, format: string, timezone: string): string { // Create date in the specified timezone const options: Intl.DateTimeFormatOptions = { timeZone: timezone, }; switch (format) { case "iso": return date.toISOString(); case "unix": return Math.floor(date.getTime() / 1000).toString(); case "unix_ms": return date.getTime().toString(); case "human": options.weekday = "short"; options.year = "numeric"; options.month = "short"; options.day = "numeric"; options.hour = "2-digit"; options.minute = "2-digit"; options.second = "2-digit"; options.hour12 = true; return date.toLocaleString("en-US", options); case "date": options.year = "numeric"; options.month = "2-digit"; options.day = "2-digit"; return date.toLocaleDateString("en-CA", options); // en-CA gives YYYY-MM-DD format case "time": options.hour = "2-digit"; options.minute = "2-digit"; options.second = "2-digit"; options.hour12 = false; return date.toLocaleTimeString("en-US", options); case "custom": // Simple custom format implementation return formatCustomDate(date, DATE_FORMAT_STRING, timezone); default: return date.toISOString(); } }
  • Helper for custom date formatting by replacing tokens like YYYY, MM, etc., in the format string.
    function formatCustomDate( date: Date, formatString: string, timezone: string ): string { const options: Intl.DateTimeFormatOptions = { timeZone: timezone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false, }; const parts = new Intl.DateTimeFormat("en-US", options).formatToParts(date); const partsMap: Record<string, string> = {}; parts.forEach((part) => { partsMap[part.type] = part.value; }); return formatString .replace(/YYYY/g, partsMap.year || "") .replace(/YY/g, (partsMap.year || "").slice(-2)) .replace(/MM/g, partsMap.month || "") .replace(/DD/g, partsMap.day || "") .replace(/HH/g, partsMap.hour || "") .replace(/mm/g, partsMap.minute || "") .replace(/ss/g, partsMap.second || ""); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TakanariShimbo/datetime-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server