Skip to main content
Glama

get_current_time

Retrieve the current date and time in a specified timezone with customizable formats (ISO, local, or full). Resolves timezone-related inaccuracies for precise timekeeping.

Instructions

Get the current date and time in a specific timezone with various formatting options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format: "iso" for ISO 8601, "local" for MM/DD/YYYY HH:MM:SS, "full" for human-readableiso
timezoneYesIANA timezone identifier (e.g., "America/New_York", "Europe/London", "Asia/Tokyo")

Implementation Reference

  • MCP tool call handler for 'get_current_time': parses arguments, invokes TimeService.getCurrentTime, and returns JSON-formatted result.
    case 'get_current_time': { const { timezone, format = 'iso' } = (args as unknown) as GetCurrentTimeParams; const result = TimeService.getCurrentTime(timezone, format); return { content: [ { type: 'text', text: JSON.stringify({ timezone: result.timezone, datetime: result.datetime, isDST: result.isDST, utcOffset: result.utcOffset, localizedFormat: result.localizedFormat, format: format, }, null, 2), }, ], }; }
  • TypeScript interface defining input parameters for get_current_time tool.
    export interface GetCurrentTimeParams { timezone: string; format?: 'iso' | 'local' | 'full'; }
  • src/index.ts:26-45 (registration)
    Tool registration in the MCP tools list, including name, description, and JSON input schema.
    { name: 'get_current_time', description: 'Get the current date and time in a specific timezone with various formatting options', inputSchema: { type: 'object', properties: { timezone: { type: 'string', description: 'IANA timezone identifier (e.g., "America/New_York", "Europe/London", "Asia/Tokyo")', }, format: { type: 'string', enum: ['iso', 'local', 'full'], description: 'Output format: "iso" for ISO 8601, "local" for MM/DD/YYYY HH:MM:SS, "full" for human-readable', default: 'iso', }, }, required: ['timezone'], }, },
  • Core implementation of getCurrentTime in TimeService class: validates timezone, computes current time info with DST and offset, formats output based on specified format.
    static getCurrentTime(timezone: string, format: 'iso' | 'local' | 'full' = 'iso'): TimezoneInfo { this.validateTimezone(timezone); const now = new Date(); const isDST = this.isDaylightSavingTime(now, timezone); const utcOffset = this.getUTCOffset(now, timezone); let datetime: string; let localizedFormat: string; switch (format) { case 'iso': datetime = new Date(now.toLocaleString('en-US', { timeZone: timezone })).toISOString(); localizedFormat = datetime; break; case 'local': datetime = now.toLocaleString('en-US', { timeZone: timezone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }); localizedFormat = datetime; break; case 'full': datetime = now.toLocaleString('en-US', { timeZone: timezone }); localizedFormat = now.toLocaleString('en-US', { timeZone: timezone, weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', timeZoneName: 'long' }); break; } return { timezone, datetime, isDST, utcOffset, localizedFormat }; }
  • TypeScript interface defining the output structure (TimezoneInfo) returned by getCurrentTime.
    export interface TimezoneInfo { timezone: string; datetime: string; isDST: boolean; utcOffset: string; localizedFormat: string; }

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/davidan90/time-node-mcp'

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