Skip to main content
Glama

convert_datetime_to_unix

Convert human-readable datetime strings to Unix timestamps for time calculations and system compatibility.

Instructions

Convert datetime time to unixtime (e.g. 2025-01-01 01:01:01 to 1746627290)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timeYes
timezoneNo

Implementation Reference

  • Handler function that takes a datetime string and optional timezone, parses it with dayjs, applies the timezone, and returns the Unix timestamp in milliseconds using valueOf().
    async ({ time, timezone }) => { const unixtime = dayjs(time).tz(getTZ(timezone)).valueOf(); return { content: [ { type: "text", text: String(unixtime), }, ], }; }, );
  • Zod input schema defining 'time' as required string and 'timezone' as optional string.
    { time: z.string(), timezone: z.string().optional(), },
  • src/index.ts:71-89 (registration)
    Registration of the 'convert_datetime_to_unix' tool using server.tool(), including name, description, schema, and inline handler.
    server.tool( "convert_datetime_to_unix", "Convert datetime time to unixtime (e.g. 2025-01-01 01:01:01 to 1746627290)", { time: z.string(), timezone: z.string().optional(), }, async ({ time, timezone }) => { const unixtime = dayjs(time).tz(getTZ(timezone)).valueOf(); return { content: [ { type: "text", text: String(unixtime), }, ], }; }, );
  • Helper function 'getTZ' that returns the provided timezone or guesses the local timezone using dayjs.tz.guess().
    const getTZ = (timezon?: string) => { return timezon || dayjs.tz.guess(); };

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/t-shiratori/time-tools-mcp-server'

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