Skip to main content
Glama
TakanariShimbo

DateTime MCP Server

get_current_time

Retrieve the current date and time in multiple formats like ISO, Unix, or human-readable, with timezone support for accurate timestamping.

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 format and timezone arguments (falling back to environment variables), gets current date, formats it using formatDateTime helper, and returns the result as text content or an error message.
    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, }; } }
  • Input schema definition for the get_current_time tool, specifying optional format (enum of supported formats) and timezone parameters with descriptions referencing environment defaults.
    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:114-131 (registration)
    Defines the Tool object for get_current_time, including name, description, and schema, which is used for registration.
    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 implements all date/time formatting logic for different formats (iso, unix, human, etc.) using Intl API and timezone support.
    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(); } }
Install Server

Other 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