Skip to main content
Glama

convert_datetime_to_unix

Convert human-readable datetime to Unix timestamp for accurate time calculations. Specify date, time, and optional timezone to generate the corresponding Unix epoch value.

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

  • The handler function that implements the core logic: parses the input datetime string using dayjs, applies the specified timezone (or guessed), computes the Unix timestamp in milliseconds using valueOf(), and returns it as a string in the tool response format.
    async ({ time, timezone }) => { const unixtime = dayjs(time).tz(getTZ(timezone)).valueOf(); return { content: [ { type: "text", text: String(unixtime), }, ], }; },
  • Input schema defined using Zod, validating 'time' as a required string (datetime) and 'timezone' as an optional string.
    { time: z.string(), timezone: z.string().optional(), },
  • src/index.ts:71-89 (registration)
    The server.tool() call that registers the 'convert_datetime_to_unix' tool, including its name, description, input schema, and handler function.
    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 used in the handler to determine the timezone: uses provided or guesses using dayjs.tz.guess().
    const getTZ = (timezon?: string) => { return timezon || dayjs.tz.guess();

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

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