Skip to main content
Glama

convert_time

Convert time from one timezone to another using source and target IANA timezone identifiers. Supports HH:MM or HH:MM:SS formats with optional YYYY-MM-DD date input for accurate timezone-aware conversions.

Instructions

Convert time from one timezone to another

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateNoOptional date in YYYY-MM-DD format. If not provided, uses current date
sourceTimezoneYesSource IANA timezone identifier
targetTimezoneYesTarget IANA timezone identifier
timeYesTime in HH:MM or HH:MM:SS format (24-hour)

Implementation Reference

  • The core handler function that performs timezone conversion, validation, DST detection, and returns detailed TimeConversionResult.
    static convertTime( sourceTimezone: string, targetTimezone: string, time: string, date?: string ): TimeConversionResult { this.validateTimezone(sourceTimezone); this.validateTimezone(targetTimezone); this.validateTime(time); const baseDate = date ? new Date(date) : new Date(); const [hours, minutes, seconds = 0] = time.split(':').map(Number); const sourceDate = new Date(baseDate); sourceDate.setHours(hours, minutes, seconds, 0); const sourceUTC = new Date(sourceDate.toLocaleString('en-US', { timeZone: 'UTC' })); const sourceLocal = new Date(sourceDate.toLocaleString('en-US', { timeZone: sourceTimezone })); const offset = sourceUTC.getTime() - sourceLocal.getTime(); const adjustedDate = new Date(sourceDate.getTime() + offset); const targetDate = new Date(adjustedDate.toLocaleString('en-US', { timeZone: targetTimezone })); const sourceInfo: TimezoneInfo = { timezone: sourceTimezone, datetime: sourceDate.toLocaleString('en-US', { timeZone: sourceTimezone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }), isDST: this.isDaylightSavingTime(sourceDate, sourceTimezone), utcOffset: this.getUTCOffset(sourceDate, sourceTimezone), localizedFormat: sourceDate.toLocaleString('en-US', { timeZone: sourceTimezone, weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZoneName: 'short' }) }; const targetInfo: TimezoneInfo = { timezone: targetTimezone, datetime: targetDate.toLocaleString('en-US', { timeZone: targetTimezone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }), isDST: this.isDaylightSavingTime(adjustedDate, targetTimezone), utcOffset: this.getUTCOffset(adjustedDate, targetTimezone), localizedFormat: adjustedDate.toLocaleString('en-US', { timeZone: targetTimezone, weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZoneName: 'short' }) }; const timeDifference = this.calculateTimeDifference( new Date(`2000-01-01T${time}`), targetDate ); return { source: sourceInfo, target: targetInfo, timeDifference }; }
  • src/index.ts:46-71 (registration)
    Registers the 'convert_time' tool in the MCP server's tools list, including name, description, and JSON input schema.
    { name: 'convert_time', description: 'Convert time from one timezone to another', inputSchema: { type: 'object', properties: { sourceTimezone: { type: 'string', description: 'Source IANA timezone identifier', }, targetTimezone: { type: 'string', description: 'Target IANA timezone identifier', }, time: { type: 'string', description: 'Time in HH:MM or HH:MM:SS format (24-hour)', }, date: { type: 'string', description: 'Optional date in YYYY-MM-DD format. If not provided, uses current date', }, }, required: ['sourceTimezone', 'targetTimezone', 'time'], }, },
  • MCP server request handler case that dispatches 'convert_time' tool calls, invokes TimeService.convertTime, and formats the JSON response.
    case 'convert_time': { const { sourceTimezone, targetTimezone, time, date } = (args as unknown) as ConvertTimeParams; const result = TimeService.convertTime(sourceTimezone, targetTimezone, time, date); return { content: [ { type: 'text', text: JSON.stringify({ conversion: { source: result.source, target: result.target, timeDifference: result.timeDifference, }, }, null, 2), }, ], }; }
  • TypeScript interface defining input parameters for the convert_time tool.
    export interface ConvertTimeParams { sourceTimezone: string; targetTimezone: string; time: string; date?: string;
  • TypeScript interface defining the output structure of the convert_time tool.
    export interface TimeConversionResult { source: TimezoneInfo; target: TimezoneInfo; timeDifference: 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